我的Yii迁移存在问题。问题是我迁移了一个代码,这个代码在成功迁移后成功完成,我尝试了另一个迁移代码,但这向我展示了迁移代码,我已经迁移的第一个代码,以及我需要迁移的第二个代码。我继续告诉yii继续迁移,之后向我发送了一个错误,表明迁移已经完成,现在这是我已经完成的迁移,因此第二次迁移无法完成。然后我删除了我的第一个迁移代码,然后继续迁移我的第二个代码。代码已成功执行但没有创建表。有没有人有这方面的解决方案,为什么我的迁移没有完成,是我执行的第二个代码,最后一个表在safeup()和safedown()在迁移文件夹中。
这是我的代码,但它再次向我发送错误。实际上我正在从trackstar项目中学习yii。所以,这是我的代码,我再次将它保留在up函数错误中。你能看看吗
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');
}
`
很好地粘贴了迁移代码,这是它现在开始向我显示的错误。这里是Dropbox的链接,这是它显示的错误enter link description here
答案 0 :(得分:1)
我在这里找到了解决方案Yii Framework - yic migrate command doesn't work
修改强>
好的,你正在使用trackstar然后你可以将你的代码放在up()和down()方法中,确保保持safeUp和safeDown方法的注释。 您可以粘贴此代码(来自您正在处理的同一项目)
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');
}
然后执行./yiic migrate
并确保您位于受保护的目录中。
一切都应该有效,我今天就这样做了。
希望有所帮助