How to change enum type column in laravel migration?

前端 未结 7 2131
挽巷
挽巷 2021-02-05 04:36

I am using Laravel 5.1 and I have a table called packages with this structure:

id              int(11)
weight          decimal(10,2)           
weight_unit     e         


        
7条回答
  •  抹茶落季
    2021-02-05 04:57

    This worked for me when adding a new enum value to the modified enum column.

    Add the following to the up() method:

    DB::statement("ALTER TABLE packages MODIFY weight_unit ENUM('Grams', 'Kgs', 'Pounds', 'new value') NOT NULL");
    

    Then in the down() method you can revert the change that was made:

    DB::statement("ALTER TABLE packages MODIFY weight_unit ENUM('Grams', 'Kgs', 'Pounds') NOT NULL");
    

    Note: before the enum value is removed it needs to be changed to another enum value that will be retained.

提交回复
热议问题