Add a new column to existing table in a migration

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

    You can add new columns within the initial Schema::create method like this:

    Schema::create('users', function($table) {
        $table->integer("paied");
        $table->string("title");
        $table->text("description");
        $table->timestamps();
    });
    

    If you have already created a table you can add additional columns to that table by creating a new migration and using the Schema::table method:

    Schema::table('users', function($table) {
        $table->string("title");
        $table->text("description");
        $table->timestamps();
    });
    

    The documentation is fairly thorough about this, and hasn't changed too much from version 3 to version 4.

提交回复
热议问题