Add extra field in migration after creating table:
First time we create a table's migration & execute migration command. After this , we realize that we have to add a new field in database.
For this, we can modify table by this easy way.
Firstly run this command for create a new migration file.
It will create a new file in migration file. Write in its up() function the following lines.
Schema::create('user_details', function ($table) {
$table->string('email');
});
and in down() function write the following lines:
Schema::create('user_details', function ($table) {
$table->drop_column('email');
});
Make sure you put the same table name which you want to edit.
Now run migration command for this file.
Thanks
First time we create a table's migration & execute migration command. After this , we realize that we have to add a new field in database.
For this, we can modify table by this easy way.
Firstly run this command for create a new migration file.
php artisan make:migration add_email_in_users_details_table
It will create a new file in migration file. Write in its up() function the following lines.
Schema::create('user_details', function ($table) {
$table->string('email');
});
and in down() function write the following lines:
Schema::create('user_details', function ($table) {
$table->drop_column('email');
});
Make sure you put the same table name which you want to edit.
Now run migration command for this file.
Thanks
No comments:
Post a Comment