Hi Everybody,
In this blog we will discuss about how to add an extra field in migration after creating a 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::table('users', function ($table) {
$table->string('fb_id');
});
and in down() function write the following lines:
Schema::table('users', function ($table) {
$table->drop_column('fb_id');
});
Make sure you put the same table name which you want to edit.
Now run migration command for this file.
php artisan migrate
Thanks.
In this blog we will discuss about how to add an extra field in migration after creating a 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.
php artisan make:migration add_fb_id_in_users_table
It will create a new file in migration file. Write in its up() function the following lines.
Schema::table('users', function ($table) {
$table->string('fb_id');
});
and in down() function write the following lines:
Schema::table('users', function ($table) {
$table->drop_column('fb_id');
});
Make sure you put the same table name which you want to edit.
Now run migration command for this file.
php artisan migrate
Thanks.