如何使字段枚举迁移yii2 [英] How to make field enum migration yii2
问题描述
<$
我在CMD窗口中使用 yii migrate / up
p $ p> 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 ,'google','twitter','github'),
'id'=> $ this-> primaryKey(),
'username'=> $ this-> string )
'user_id'=> $ this->整数(11),
'created_at'=> $ this->整数(11),
'updated_at'= > $ this-> integer(11),
],$ tableOptions);
}
没有枚举()方法在因为不是每个DB都支持ENUM字段。您可以手动执行:
'social_media'=> ENUM('facebook','google','twitter','github'),
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);
}
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')",
这篇关于如何使字段枚举迁移yii2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!