如何使字段枚举迁移yii2 [英] How to make field enum migration yii2

查看:490
本文介绍了如何使字段枚举迁移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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆