Add sql table column before or after specific other column - by migrations in Laravel 4.1

前端 未结 5 1465
遇见更好的自我
遇见更好的自我 2020-12-14 05:56

Table \'users\':

|id|name|address|post_code|deleted_at|created_at|

and I want add column \'phone_nr\' somewhere between \'id\' and \'delete

5条回答
  •  忘掉有多难
    2020-12-14 06:17

    Yes. Create a new migration using php artisan migrate:make update_users_table.

    Then use the table command as follows (if you're using MySQL!):

    Schema::table('users', function($table)
    {
        $table->string('phone_nr')->after('id');
    });
    

    Once you've finished your migration, save it and run it using php artisan migrate and your table will be updated.

    Documentation: https://laravel.com/docs/4.2/migrations#column-modifiers

提交回复
热议问题