我的Yii遷移有問題。問題是我遷移了一個成功遷移後成功完成的代碼,我嘗試了另一個遷移代碼,但是它向我展示了遷移代碼,這是我已遷移的第一個遷移代碼,也是我需要遷移的第二個遷移代碼。我只是繼續告訴yii繼續遷移,然後給我一個錯誤,說明遷移已經完成,現在這是我已經完成的遷移,因此第二次遷移無法完成。然後,我刪除了我的第一個遷移代碼,並繼續遷移我的第二個代碼。該代碼已成功執行,但沒有創建表。有沒有人有解決方案,爲什麼我的遷移沒有完成,是我的第二個代碼,我已經執行,最後一個表是在遷移文件夾中的safeup()和safedown()。Yii遷移不起作用
這是我的代碼,但它再次向我發送錯誤。其實我是從trackstar項目學習yii。所以,這個我的代碼再次,我保持在上功能再次錯誤。你可以看看
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
好吧,現在有一個錯誤說明遷移失敗。所有後來的遷移都被取消 – 2014-08-28 12:37:19
如果你的數據庫創建不需要事務,你可以嘗試把你的代碼放在up方法而不是safeup方法中,@ Ivan Buttinoni回答於:http://stackoverflow.com/questions/17444095/yii-migration-tables-are-not-created,如果你有錯誤,請把它粘貼在這裏。 。 – hsabbagh 2014-08-28 12:47:51
我使用的yiic遷移降功能 – 2014-08-28 12:55:51