"Yii2.0.4" Supplement to database migration migration in advanced templates

Source: Internet
Author: User
Tags createindex yii

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.