yii2如何进行字段枚举迁移 [英] How to make field enum migration yii2
本文介绍了yii2如何进行字段枚举迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 CMD 窗口上使用 yii migrate/up
时创建字段 ENUM,结果是错误.
I make field ENUM and the result is error when I use yii migrate/up
on CMD windows.
public function up()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable('{{%user_social_media}}', [
'social_media' => $this->ENUM('facebook', 'google', 'twitter', 'github'),
'id' => $this->primaryKey(),
'username' => $this->string(),
'user_id' => $this->integer(11),
'created_at' => $this->integer(11),
'updated_at' => $this->integer(11),
], $tableOptions);
}
推荐答案
目前没有 enum() 方法,因为不是每个 DB 都支持 ENUM 字段.您可以手动完成:
There is no enum() method at the moment since not every DB is supporting ENUM fields. You can do it manually though:
'social_media' => "ENUM('facebook', 'google', 'twitter', 'github')",
注意:此解决方案仅适用于 Mysql
Note: This solution is for Mysql only
有关 Postgresql 的相关内容,请访问 此处
For related Postgresql content visit here
这篇关于yii2如何进行字段枚举迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文