Skip to content
This repository

doctrine:fixtures:load --purge-with-truncate fails #50

Open
fkrauthan opened this Issue July 11, 2012 · 12 comments

8 participants

Florian Krauthan Christophe Coevoet Steve Müller Robert (Jamie) Munro ARTACK WebLab Aaron Scherer Luis Hdez Matthieu Napoli
Florian Krauthan

If I run app/console doctrine:fixtures:load --purge-with-truncate I get the error SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint

Christophe Coevoet
Collaborator
stof commented July 11, 2012

This is a restriction in MySQL 5.5: it cannot truncate when there is a foreign key. This is exactly the reason why using TRUNCATE is not the default behavior anymore.

Florian Krauthan

But can't you delete all data then TRUNCATE all tables and then importing all new datas?

Steve Müller

This issue could be fixed by disabling the foreign key checks before truncating (SET foreign_key_checks = 0). Would that be an option worth thinking about? I don't know how other RDMS manage this issue...

Christophe Coevoet
Collaborator
stof commented August 20, 2012

@deeky666 this has already been suggested, and @beberlei rejected it.

Robert (Jamie) Munro

doctrine:fixtures:load fails with foreign key errors for me either with or without the --purge-with-truncate option. Is this the same issue, or something deeper?

Steve Müller

Foreign keys are also checked when truncating a table, thus it's the same problem...

ARTACK WebLab

Run into the same problem today. I would go for another option to disable foreign key checks for truncate.

Aaron Scherer

Have we found a solution for this yet?

Steve Müller

According to @guilhermeblanco this will be fixed in 2.0

Gordon Franke gimler referenced this issue in instaclick/ICBaseTestBundle April 22, 2013
Merged

Fix mysql 5.5 truncate problem #26

Luis Hdez

Any news on this? why "SET foreign_key_checks = 0;" proposal has been rejected ?

I think SET foreign_key_checks = 0; it's the only possible way to solve this problem. That's why it exists. Because if you have a relation with foreign keys between each other, there is no other way.

So this command doesn't make sense at all to me. :(

Steve Müller

Please see also the discussion here: doctrine/data-fixtures#127

Matthieu Napoli

So there is still no solution available for this problem? Even a hacky one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.