Add a new column to existing table in a migration

前端 未结 12 2651
离开以前
离开以前 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:56

    I'll add on to mike3875's answer for future readers using Laravel 5.1 and onward.

    To make things quicker, you can use the flag "--table" like this:

    php artisan make:migration add_paid_to_users --table="users"
    

    This will add the up and down method content automatically:

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            //
        });
    }
    

    Similarily, you can use the --create["table_name"] option when creating new migrations which will add more boilerplate to your migrations. Small point, but helpful when doing loads of them!

提交回复
热议问题