0

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

trejder
  • 17,148
  • 27
  • 124
  • 216
samhu kiklsk
  • 153
  • 1
  • 1
  • 7

1 Answers1

1

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

Community
  • 1
  • 1
Hamzeh
  • 167
  • 1
  • 4
  • 13
  • well now there is a error saying migration failed. all later migration are cancelled – samhu kiklsk Aug 28 '14 at 12:37
  • you can try to put your code in the up method instead of the safeup method if your creation of database don't require transactions , from @Ivan Buttinoni answer at http://stackoverflow.com/questions/17444095/yii-migration-tables-are-not-created , if you have an error please paste it here. . – Hamzeh Aug 28 '14 at 12:47
  • i used the yiic migrate down function – samhu kiklsk Aug 28 '14 at 12:55
  • can you paste the error please, does it cause error when you do ./yiic migrate or error on the code itself ? – Hamzeh Aug 28 '14 at 13:06
  • yes migrate down will fail because you dont have any tables created, you should do migrate and get the tables created first, can you please check my edit here. and try to migrate from the start . just remove m******_create_issue_user_and_assignment_tables.php and start again and tell me what you get – Hamzeh Aug 28 '14 at 13:34
  • hey thanks, the table has been created, well needed to do come editing of my own, but thanks. it was all i need to start back again. and yes one more question to you, do i have to delete my previous codes to migrate new one's, because when ever i m trying to migrate, it shows 2 migration files. and does not allow the second migration to happen until i delete the first one. – samhu kiklsk Aug 28 '14 at 13:54
  • Well everything worked well. tables created. thanks a lot for your help. I still have a question. Should i have to delete the previous migration code to excecute the new one, i m asking this question because when ever i m try migrating, the migration cmd shows me the previous migration code too, and when i migrate it executes the first one sending me error that the migration has already been performed, with that it does not allow me to migrate the other code. what should i do, will deleting the previous code effect the codes and migration that has been done. – samhu kiklsk Aug 28 '14 at 14:05
  • no you dont need to delete your old files, it will automatically skip the old ones. its just a problem with this one because it says in the book that you have to put it on safeUp() and mess things up i guess. glad it helps. – Hamzeh Aug 28 '14 at 14:06
  • thanks. it was troubling my mind too much, but in this case i just deleted the old file to execute the new one. so, will deleting the file cause any sot of probelm – samhu kiklsk Aug 28 '14 at 14:10
  • if it doesnt create the tables such like your case then it doesnt cause any problems. and if you created the tables and want to go back you can use ./yiic migrate down – Hamzeh Aug 28 '14 at 14:16