Make column not nullable in a Laravel migration

前端 未结 4 727
醉酒成梦
醉酒成梦 2020-12-12 17:32

I\'m writing a migration to make certain columns in a table nullable right now. For the down function, I of course want to make those columns not nullable

4条回答
  •  自闭症患者
    2020-12-12 18:17

    You can just declare the column again without ->nullable() and use ->change

    public function up()
    {
        Schema::table('table_name', function (Blueprint $table) {
            $table->type('column')->change();
        });
    }
    
    public function down()
    {
        Schema::table('table_name', function ($table) {
            $table->type('column')->nullable()->change();
        });
    }
    

提交回复
热议问题