Add a new column to existing table in a migration

前端 未结 12 2629
离开以前
离开以前 2020-11-28 17:09

I can\'t figure out how to add a new column to my existing database table using the Laravel framework.

I tried to edit the migration file using...



        
12条回答
  •  粉色の甜心
    2020-11-28 17:59

    this things is worked on laravel 5.1.

    first, on your terminal execute this code

    php artisan make:migration add_paid_to_users --table=users
    

    after that go to your project directory and expand directory database - migration and edit file add_paid_to_users.php, add this code

    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
             $table->string('paid'); //just add this line
        });
    }
    

    after that go back to your terminal and execute this command

    php artisan migrate
    

    hope this help.

提交回复
热议问题