A
A
Andrey Tokmakov2016-03-22 08:45:36
Yii
Andrey Tokmakov, 2016-03-22 08:45:36

Why didn't the transaction work when rolling back a migration in yii2?

There is a migration written via safeUp()/safeDown().
Performed migration, decided to rollback

public function safeDown()
    {
        $this->dropTable('{{%post_tags}}');
        $this->dropTable('{{%tags}}');
        $this->dropTable('{{%category}}');
        $this->dropTable('{{%post}}');
    }

It turned out an error due to FK (my cant), as a result, 2 tables remained in the database (category and post).
And if I'm not mistaken (maybe it was before, but it didn't seem to be), an entry appeared in the migration table m000000_000000_base with the date 1456394833 (February 25)
What did I do wrong? Or what is the problem with the transaction?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mylistryx, 2016-03-22
@NPC

If the database is MySQL, then there, if my memory serves me, transactions for creating / deleting tables do not work. Faced a similar problem when creating tables, for example:
Create table A, add foreign key A to B. All this is wrapped in safeUp. If there is an error in the description of creating key B, then the migration will create table A, and an exception will be thrown to create the key. Having edited this migration, when you try to apply it again, an exception will fly out that table A already exists.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question