我的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的链接,这是它在这里的链接描述中显示的错误
我也遇到了同样的问题。您应该删除up方法。
我在这里找到了Yii Framework-yic migrate命令的解决方案;t工作
编辑:
好吧,你正在做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
并确保您在受保护的目录中。一切都会好起来的,我今天已经做到了。
希望它能帮助