2019-05-20 14:21:53 0 评论 Yii 2.0 Boy.Lee

Yii 2.0框架使用Migration创建BigInt类型主键(PK)

有些时候我们需要新建BigInt类型的主键来代替常规的Int类型主键,在Yii 2.0框架的Migraion工具中可以直接使用如下命令来实现:

 

        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
        }
        
        
        $this->createTable('captcha', [
                'cap_id' => $this->bigPrimaryKey()->notNull()->unsigned(),
                'cap_type_id' => "tinyint(3) NOT NULL COMMENT 'API: captcha type for yiilib.com website, 1 - normal words, 2 - number, 3 - pic maybe' ",
                'cap_scenario' => $this->string(45),
                'cap_correctValue' => $this->string(45)->notNull(),
                'cap_expiredDate' => $this->dateTime(),
        ], $tableOptions);