For Postgresql Yii fixture handling leads to referential integrity breakdown

Hi there everybody,

today we (my team and me) just stumbled over a weird error. We have a foreign key in place between the two tables order and order_items, thus meaning an order HAS_MANY items. Unfortunately we did something wrong with the fixture setup so there was a order_id = 7 in order_items but no corresponding id = 7 in the order table.

Now the weirdo stuff happens: Yii fixture manager just writes the fixtures to the database without complaining about the referential integrity violation. The dataset in the tables is really there as we can see on the command line. We are not able to delete and reenter the same row, so the foreign_key constraint seems to work. We also can not delete the foreign_key and add it again because it correctly complains about the row.

I searched the documentation and the Postgres bug reports for how that kind of integrity check bypassing may happen, but I did not found anything. I do not think, it is a good idea to circumvent integrity checking, if enforcing it afterwards is not guaranteed.

Maybe it would be a better idea to delete the integrity checks before inserting and reenable them afterwards? I found a script that could be useful for this: http://blog.hagander.net/archives/131-Automatically-dropping-and-creating-constraints.html

can you verify that behavior?

Best regards,

Bergtroll