Laravel migration table field's type change

后端 未结 7 1499
难免孤独
难免孤独 2020-12-08 12:45

Following is my file 2015_09_14_051851_create_orders_table.php. And I want to change $table->integer(\'category_id\'); as a string with new migratio

7条回答
  •  生来不讨喜
    2020-12-08 13:19

    The standard solution didn't work for me, when changing the type from TEXT to LONGTEXT.

    I had to it like this:

    public function up()
    {
        DB::statement('ALTER TABLE mytable MODIFY mycolumn  LONGTEXT;');
    }
    
    public function down()
    {
        DB::statement('ALTER TABLE mytable MODIFY mycolumn TEXT;');
    }
    

    This could be a Doctrine issue. More information here.

    Another way to do it is to use the string() method, and set the value to the text type max length:

        Schema::table('mytable', function ($table) {
            // Will set the type to LONGTEXT.
            $table->string('mycolumn', 4294967295)->change();
        });
    

提交回复
热议问题