Make column not nullable in a Laravel migration

前端 未结 4 733
醉酒成梦
醉酒成梦 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条回答
  •  Happy的楠姐
    2020-12-12 18:14

    First run this:

    composer require doctrine/dbal

    Then create a migration that will alter the table like so:

    php artisan make:migration fix_whatever_table_name_here

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

提交回复
热议问题