Alter ENUM column and add value to that column in Laravel Alter ENUM column and add value to that column in Laravel laravel laravel

Alter ENUM column and add value to that column in Laravel


After all, I figure out to find a solution. Thanks to all fellows for enlightening me. :)

/**     * Schema table name to migrate     * @var string     */    public $set_schema_table = 'bt_user_level_attempt';    /**     * Run the migrations.     *     * @return void     */    public function up()    {        DB::statement("ALTER TABLE ".$this->set_schema_table." MODIFY COLUMN status ENUM('PROGRESS', 'STOPPED', 'COMPLETED', 'PASSED') NOT NULL DEFAULT 'PROGRESS'");    }    /**     * Reverse the migrations.     *     * @return void     */    public function down()    {        DB::statement("ALTER TABLE ".$this->set_schema_table." MODIFY COLUMN status ENUM('PROGRESS', 'STOPPED', 'COMPLETED') NOT NULL DEFAULT 'PROGRESS'");    }


You should try with DB::statement method:

Use the DB::statement method:

DB::statement("ALTER TABLE ".$this->set_schema_table." CHANGE COLUMN status ENUM('PROGRESS', 'STOPPED', 'COMPLETED','PASSED') NOT NULL DEFAULT 'PROGRESS'");


Please refer to documentation:

Only the following column types can be "changed": bigInteger, binary, boolean, date, dateTime, dateTimeTz, decimal, integer, json, longText, mediumText, smallInteger, string, text, time, unsignedBigInteger, unsignedInteger and unsignedSmallInteger.

So the ENUM cannot be modified using simple migration syntax. But you can migrate your column using a custom statement:

DB::statement("ALTER TABLE ".$this->set_schema_table." MODIFY COLUMN status ENUM('PROGRESS', 'STOPPED', 'COMPLETED','PASSED') NOT NULL DEFAULT 'PROGRESS'");