如何使字段枚举迁移 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屋!
查看全文