Friday, January 22, 2016

Add extra column in migration after creating a table in Laravel 5.2

Hello Everyone,

Today, we will discuss about how to add an extra column 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 column in table.

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_column_name_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('column_name');
          });


and in down() function write the following lines:

Schema::table('users', function ($table) {
            $table->drop_column('
column_name');

          });

Make sure you put the same table name which you want to edit.

Now run migration command for this file.

php artisan migrate

Thanks.

No comments:

Post a Comment