database migration in Yii

时间秒杀一切 提交于 2019-12-03 00:39:05

Just supply them as non-associative values in the array like this:

$this-> createTable('{{users}}',array(
   'id' => 'pk',
   'username' => 'VARCHAR (80) NOT NULL',
   'password' => 'VARCHAR (80) NOT NULL',
   'email' => 'VARCHAR (128) NOT NULL',
   'activekey' => 'VARCHAR (128) NOT NULL DEFAULT \'\'',
   'createtime' => 'INTEGER (10) NOT NULL DEFAULT \'0\' ',
   'lastvisit' => 'INTEGER (10) NOT NULL DEFAULT \'0\' ',
   'superuser' => 'INTEGER (1) NOT NULL DEFAULT \'0\' ',
   'status'=> 'INTEGER (1) NOT NULL DEFAULT \'0\' ',
   'UNIQUE KEY `username` (`username`)',
   'UNIQUE KEY `email` (`email`)',
   'KEY `status` (`status`)',
   'KEY `superuser` (`superuser`)',
));

This way they will be added to the end of the create statement without any change.

$this->createTable('{{users}}',
    array(
        'id' => 'pk',
        'username' => 'varchar(80) NOT NULL',
        'password' => 'varchar(80) NOT NULL',
        'email' => 'varchar(128) NOT NULL',
        'activkey' => 'varchar(128) NOT NULL DEFAULT \'\'',
        'createtime' => 'integer(10) NOT NULL DEFAULT \'0\'',
        'lastvisit' => 'integer(10) NOT NULL DEFAULT \'0\'',
        'superuser' => 'integer(1) NOT NULL DEFAULT \'0\'',
        'status' => 'integer(1) NOT NULL DEFAULT \'0\'',
    ),
);

$this->createIndex('username', '{{user}}', 'username', true);
$this->createIndex('email', '{{user}}', 'email', true);
$this->createIndex('superuser', '{{user}}', 'superuser', false);
$this->createIndex('status', '{{user}}', 'status', false);

See http://www.yiiframework.com/doc/api/1.1/CDbMigration#createIndex-detail for more details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!