2016-08-23 48 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 –