![$blog_data[0]->title](https://theeducation.net/public/frontend/assets/blog_images/632aa1af76811image053127.jpg)
What is Migration in Laravel:
Let's Understand this better.
After Installing Laravel , let's understand migration.
Create a migration and understand the structure:
To generate a migration you need run a command.
php artisan make:migration create_posts_table --create=posts
this will generate a contacts table file in database\migrations
folder.
The file consist of new class extending the migration class of LARAVEL.
The new class consist of 2 major function up() & down()
. The up()
function holds all information about migrating the file.
public function up()
{
Schema::create('contacts', function (Blueprint $table)
{
$table->id();
$table->string('name');
$table->string('mobile_no');
$table->boolean('status');
$table->timestamps();
});
}
whereas down()
function holds information about reversing the migration action.
public function down()
{
Schema::dropIfExists('contacts');
}
Run & Rollback The Migration:
To run a migration we need to use the command.
php artisan migrate
For rolling back latest migration we have command.
php artisan migrate:rollback
when we have to rollback till specific steps we can pass steps in rollback command like.
php artisan migrate:rollback --step (this command will delete the latest migration migrations)
php artisan migrate:rollback --step=2 (this command will delete 2 migrations)
this will rollback the migration upto 3 step starting from latest.
if you want to check that if a new migration is created and not add in the database.
php artisan migrate:status
if you want to add a column in a existing table using migration.
php artisan make:migration add_email_column_in_contact_table --table=contacts
if you want to delete all the database.
php artisan migrate:reset
if you want to refresh all the database.
php artisan migrate:refresh
if you want to delete a specific migration file.
php artisan migrate:rollback --path=database\migrations\file_name
0 Comments
Post Comment