Add a new column to existing table in a migration

前端 未结 12 2624
离开以前
离开以前 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 18:00

    Although a migration file is best practice as others have mentioned, in a pinch you can also add a column with tinker.

    $ php artisan tinker
    

    Here's an example one-liner for the terminal:

    Schema::table('users', function(\Illuminate\Database\Schema\Blueprint $table){ $table->integer('paid'); })
    



    (Here it is formatted for readability)

    Schema::table('users', function(\Illuminate\Database\Schema\Blueprint $table){ 
        $table->integer('paid'); 
    });
    

提交回复
热议问题