In order to doing migration in Yii I used this lines
<?php
class m110714_122129_users extends CDbMigration
{
public function up()
{
$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\' ',
));
}
public function down()
{
echo "m110714_122129_users does not support migration down.\n";
return false;
}
/*
// Use safeUp/safeDown to do migration with transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
To get
CREATE TABLE IF NOT EXISTS `nt_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`password` varchar(128) NOT NULL,
`email` varchar(128) NOT NULL,
`activkey` varchar(128) NOT NULL DEFAULT '',
`createtime` int(10) NOT NULL DEFAULT '0',
`lastvisit` int(10) NOT NULL DEFAULT '0',
`superuser` int(1) NOT NULL DEFAULT '0',
`status` int(1) NOT NULL DEFAULT '0',
);
But now I want to make some changes like doing unique key
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`),
KEY `status` (`status`),
KEY `superuser` (`superuser`)
so how to make that? I searched Yii documentation but not found any thing. So any help will be highly appreciated..
See http://www.yiiframework.com/doc/api/1.1/CDbMigration#createIndex-detail for more details.
Just supply them as non-associative values in the array like this:
This way they will be added to the end of the create statement without any change.