2016-08-23 49 views
7

我使字段ENUM和结果是错误时,我在CMD窗口上使用yii migrate/up如何使字段枚举迁移yii2

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); 
} 

When I migrate/up error

回答

19

有一个在因为不是每个DB是支持ENUM领域暂时没有枚举()方法。你可以做手工,但:

'social_media' => "ENUM('facebook', 'google', 'twitter', 'github')", 
+0

好的解决感谢.. – CrashBurn

+0

然后将其标记为sloved,请:) –

+2

以防万一它的公开讨论它在未来的变化:https://github.com/ yiisoft/yii2 /问题/ 9797 –