如何在laravel迁移中更改枚举类型列? [英] How to change enum type column in laravel migration?
本文介绍了如何在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迁移中更改枚举类型列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文