I have a issue with my Yii migration. The problem is i migrated a code which was done sucessfully after the successful migration i tried another migration code, but that showed me to migration codes, the first one that i had already migrated and the second one that i needed to migrate. I just went on and told yii to continue to migrate, which thereafter sends me a error that the migration has already been done, now that was the migration that i had already done so the second migration could not be done. I then deleted the my first migration code and went on to migrate my second code. the code was successfully executed but there was no table created. Does anyone has a solution to this, why my migration is not being done, and yes my second code that i had executed, the last one the tables are on the safeup() and safedown() in the migration folder.
this is my code but it again sends me error. actually i m learning yii from trackstar project. So, this my code again, i kept it in the up function again error. could you have a look
public function up()
{
//create the issue table
$this->createTable('tbl_issue', array(
'id' => 'pk',
'name' => 'string NOT NULL',
'description' => 'text',
'project_id' => 'int(11) DEFAULT NULL',
'type_id' => 'int(11) DEFAULT NULL',
'status_id' => 'int(11) DEFAULT NULL',
'owner_id' => 'int(11) DEFAULT NULL',
'requester_id' => 'int(11) DEFAULT NULL',
'create_time' => 'datetime DEFAULT NULL',
'create_user_id' => 'int(11) DEFAULT NULL',
'update_time' => 'datetime DEFAULT NULL',
'update_user_id' => 'int(11) DEFAULT NULL',
), 'ENGINE=InnoDB');
//create the user table
$this->createTable('tbl_user', array(
'id' => 'pk',
'username' => 'string NOT NULL',
'email' => 'string NOT NULL',
'password' => 'string NOT NULL',
'last_login_time' => 'datetime DEFAULT NULL',
'create_time' => 'datetime DEFAULT NULL',
'create_user_id' => 'int(11) DEFAULT NULL',
'update_time' => 'datetime DEFAULT NULL',
'update_user_id' => 'int(11) DEFAULT NULL',
), 'ENGINE=InnoDB');
//create the assignment table that allows for many-to-many
//relationship between projects and users
$this->createTable('tbl_project_user_assignment', array(
'project_id' => 'int(11) NOT NULL',
'user_id' => 'int(11) NOT NULL',
'PRIMARY KEY (`project_id`,`user_id`)',
), 'ENGINE=InnoDB');
//foreign key relationships
//the tbl_issue.project_id is a reference to tbl_project.id
$this->addForeignKey("fk_issue_project", "tbl_issue", "project_
id", "tbl_project", "id", "CASCADE", "RESTRICT");
//the tbl_issue.owner_id is a reference to tbl_user.id
$this->addForeignKey("fk_issue_owner", "tbl_issue", "owner_id",
"tbl_user", "id", "CASCADE", "RESTRICT");
//the tbl_issue.requester_id is a reference to tbl_user.id
$this->addForeignKey("fk_issue_requester", "tbl_issue",
"requester_id", "tbl_user", "id", "CASCADE", "RESTRICT");
//the tbl_project_user_assignment.project_id is a reference totbl_project.id
$this->addForeignKey("fk_project_user", "tbl_project_user_
assignment", "project_id", "tbl_project", "id", "CASCADE",
"RESTRICT");
//the tbl_project_user_assignment.user_id is a reference to tbl_user.id
$this->addForeignKey("fk_user_project", "tbl_project_user_
assignment", "user_id", "tbl_user", "id", "CASCADE", "RESTRICT");
}
public function down()
{
$this->truncateTable('tbl_project_user_assignment');
$this->truncateTable('tbl_issue');
$this->truncateTable('tbl_user');
$this->dropTable('tbl_project_user_assignment');
$this->dropTable('tbl_issue');
$this->dropTable('tbl_user');
}
`
well the migration code are pasted up this is the error it has started showing me now. here the link to the dropbox, this is the error it has been showingenter link description here
i had the same problem. you should remove the up method.
I found the solution here Yii Framework - yic migrate command doesn't work
EDIT:
Ok you are doing the trackstar then you can put your code inside the up() and down() methods, make sure to keep the safeUp and safeDown methods commented. you can paste this code (its from the same project you are working on)
public function up() {
//create the issue table
$this->createTable('tbl_issue', array(
'id' => 'pk','name' => 'string NOT NULL', 'description' => 'text', 'project_id' => 'int(11) DEFAULT NULL', 'type_id' => 'int(11) DEFAULT NULL', 'status_id' => 'int(11) DEFAULT NULL', 'owner_id' => 'int(11) DEFAULT NULL', 'requester_id' => 'int(11) DEFAULT NULL', 'create_time' => 'datetime DEFAULT NULL', 'create_user_id' => 'int(11) DEFAULT NULL',
'update_time' => 'datetime DEFAULT NULL', 'update_user_id' => 'int(11) DEFAULT NULL', ), 'ENGINE=InnoDB');
//create the user table
$this->createTable('tbl_user', array(
'id' => 'pk', 'username' => 'string NOT NULL', 'email' => 'string NOT NULL', 'password' => 'string NOT NULL', 'last_login_time' => 'datetime DEFAULT NULL', 'create_time' => 'datetime DEFAULT NULL', 'create_user_id' => 'int(11) DEFAULT NULL', 'update_time' => 'datetime DEFAULT NULL', 'update_user_id' => 'int(11) DEFAULT NULL',
), 'ENGINE=InnoDB');
//create the assignment table that allows for many-to-many
//relationship between projects and users
$this->createTable('tbl_project_user_assignment', array( 'project_id' => 'int(11) NOT NULL', 'user_id' => 'int(11) NOT NULL', 'PRIMARY KEY (`project_id`,`user_id`)',
), 'ENGINE=InnoDB');
//foreign key relationships
//the tbl_issue.project_id is a reference to tbl_project.id
$this->addForeignKey("fk_issue_project", "tbl_issue", "project_
id", "tbl_project", "id", "CASCADE", "RESTRICT");
//the tbl_issue.owner_id is a reference to tbl_user.id
$this->addForeignKey("fk_issue_owner", "tbl_issue", "owner_id", "tbl_user", "id", "CASCADE", "RESTRICT");
//the tbl_issue.requester_id is a reference to tbl_user.id
$this->addForeignKey("fk_issue_requester", "tbl_issue", "requester_id", "tbl_user", "id", "CASCADE", "RESTRICT");
//the tbl_project_user_assignment.project_id is a reference to tbl_project.id
$this->addForeignKey("fk_project_user", "tbl_project_user_
assignment", "project_id", "tbl_project", "id", "CASCADE", "RESTRICT");
//the tbl_project_user_assignment.user_id is a reference to tbl_user.id
$this->addForeignKey("fk_user_project", "tbl_project_user_
assignment", "user_id", "tbl_user", "id", "CASCADE", "RESTRICT");
}
public function down() {
$this->truncateTable('tbl_project_user_assignment');
$this->truncateTable('tbl_issue');
$this->truncateTable('tbl_user');
$this->dropTable('tbl_project_user_assignment');
$this->dropTable('tbl_issue');
$this->dropTable('tbl_user');
}
and then do ./yiic migrate
and make sure you are in the protected directory.
and everything should work, i've did that today.
Hope it helps