Josh Nankin
Josh Nankin

Reputation: 2568

Doctrine/Symfony generated migrations out of order

I'm not sure if this is a bug, but it sure seems like one to me.

When I generate migrations using generate-migrations-diff involving tables that have foreign keys in Symfony, the migrations that result seem to be out of order.

For instance, assuming I have a foreign key in table A to table B, and I delete table B and the referencing field in Table A, the first migration drops Table B and the column in Table A whereas the second migration then drops the foreign key constraint in Table A. The first migration does not work as the field in Table A with the foreign key constraint cannot be dropped, nor can Table B be dropped because of the foreign key constraint.

What should happen is that the foreign key constraint should be dropped first, and then the table and fields should be dropped.

I'm using mysql 5.1.37 as my DBMS.

Here's some of the generated code:

class Version94 extends Doctrine_Migration_Base
{
    public function up()
    {
        $this->dropTable('B');
        $this->removeColumn('A', 'b_id');
    }
.
.
.


class Version95 extends Doctrine_Migration_Base
{
    public function up()
    {
        $this->dropForeignKey('A', 'a_b_id_b_id');
    }

Upvotes: 2

Views: 833

Answers (1)

Jeremy Kauffman
Jeremy Kauffman

Reputation: 10413

It's almost certainly a bug. In my experience, doctrine:generate-migrations-diff is very unreliable and will generate incorrect migrations for more complex changes.

You can report the issue here.

Upvotes: 1

Related Questions