1. File path: advanced/console/migrations/m130524_201442_init.php
2, add the point: Increase the constraint "username" "Email" Authentication uniqueness:
Original code:
<?phpuse yii\db\Schema;use yii\db\Migration;class m130524_201442_init extends Migration{ public function up () { $tableOptions = null; if ($this->db->drivername === ' mysql ') { // http://stackoverflow.com/questions/766809/ whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci $tableOptions = ' character set utf8 collate utf8_ Unicode_ci engine=innodb '; } $this->createtable (' {{%user}} ', [ ' id ' => schema::type_pk, ' username ' => Schema:: type_string . ' not null ', ' Auth_key ' => Schema::TYPE_STRING . ' (+) not null ', ' Password_hash ' => schema::type_ string . ' not null ', ' Password_reset_token ' => Schema::TYPE_STRING, ' email ' => Schema::TYPE_STRING . ' not null ', ' status ' => schema::type_ smallint . ' not null default 10 ', ' CReated_at ' => Schema::TYPE_INTEGER . ' not null ', ' Updated_at ' => Schema::TYPE_INTEGER . ' not null ', ], $tableOptions); } public function down () { $this->droptable (' {{%user}} '); }}
Supplemental Code:
<?phpuse yii\db\Schema;use yii\db\Migration;class m130524_201442_init extends Migration{ public function safeup () { $tableOptions = null; if ($this->db->drivername === ' mysql ') { // http://stackoverflow.com/questions/766809/ whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci $tableOptions = ' character set utf8 collate utf8_ Unicode_ci engine=innodb '; } $this->createtable (' {{%user}} ', [ ' id ' => schema::type_pk, ' username ' => schema::type_string . ' not null ', ' Auth_key ' => Schema::TYPE_STRING . ' (+) not null ', ' Password_hash ' => schema::type _string . ' not null ', ' Password_reset_token ' => Schema::TYPE_STRING, ' email ' => Schema::TYPE_STRING . ' not null ', ' status ' => schema::type_ smallint . ' not null default 10 ', &nbsP; ' Created_at ' => Schema::TYPE_INTEGER . ' not null ', ' Updated_at ' => Schema::TYPE_INTEGER . ' not null ', ], $tableOptions); $this->createindex (' username ', ' {{%user}} ', ' username ', true); $this->createindex (' email ', ' {{%user}} ', ' Email ', true); } public function safedown () { $this->droptable (' {{%user}} '); }}
"Yii2.0.4" Supplement to database migration migration in advanced templates