Friday, November 6, 2015

Add extra field in migration after creating table in Laravel 5.1

Hello Everyone,

In this blog we will discuss about 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.

Lets suppose that we have to add email field in users table.
Firstly run this command for create a new migration file.

php artisan make:migration add_email_in_users_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('users', 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.

No comments:

Post a Comment