如何在laravel迁移中更改枚举类型列?

编程入门 行业动态 更新时间:2024-10-28 10:33:48
本文介绍了如何在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迁移中更改枚举类型列?

本文发布于:2023-10-17 22:04:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502207.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   如何在   laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!