0

我的 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');
    }
`

好吧,迁移代码已粘贴,这是它现在开始向我显示的错误。这里是保管箱的链接,这是它一直显示的错误在此处输入链接描述

4

1 回答 1

1

我有同样的问题。你应该删除 up 方法。

我在这里找到了解决方案Yii Framework - yic migrate 命令不起作用

编辑:

好的,你正在做 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 确保您在受保护的目录中。一切都应该工作,我今天已经做到了。

希望能帮助到你

于 2014-08-28T11:40:42.073 回答