本文介绍了如何在laravel迁移中更改枚举类型列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Laravel 5.1 ,并且我有一个名为packages的表,其结构如下:
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 enum('Kg.', 'Gm.')我想将weight_unit枚举更改为:
weight_unit enum('Grams','Kgs.','Pounds')
为此,我创建了以下迁移:
For this I create the following migration:
public function up() { Schema::table('packages', function ($table) { $table->enum('weight_unit', array('Grams','Kgs.','Pounds'))->nullable()->change(); }); }但是当我运行迁移时,我收到一个错误:
But when I run the migration I receive an error:
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.如何更改此枚举?
推荐答案使用DB::statement方法:
DB::statement("ALTER TABLE packages MODIFY COLUMN weight_unit ENUM('Grams', 'Kgs', 'Pounds')");更多推荐
如何在laravel迁移中更改枚举类型列?
发布评论