Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FK error by purge (incorrect order of deleting from tables) #370

Open
maximmandrik opened this issue Jun 1, 2022 · 3 comments
Open

FK error by purge (incorrect order of deleting from tables) #370

maximmandrik opened this issue Jun 1, 2022 · 3 comments

Comments

@maximmandrik
Copy link

maximmandrik commented Jun 1, 2022

There is such an tables architecture:

Execute app:fixtures:load with purge.

When automatically deleting from network_switches_ports, I get an error:

[critical] Error thrown while running command "doctrine:fixtures:load". Message: "An exception occurred while executing a query: SQLSTATE[23503]: Foreign key violation: 7 ERROR:  update or delete on table "network_switches_ports" violates foreign key constraint "fk_47b01a1e7449a980" on table "hardware_ip_cameras"
DETAIL:  Key (id)=(1ece1947-037b-6c14-90d9-8784702a4f98) is still referenced from table "hardware_ip_cameras"."

FK from hardware_ip_cameras.

If you delete in the correct order, then such an error would not have occurred.

Correct order of deleting from tables:
hardware_ip_cameras, hardware_video_servers, network_switches_ports, hardware_network_switches, hardware.

@greg0ire
Copy link
Member

greg0ire commented Jun 1, 2022

Please provide a stack trace

@fd6130
Copy link

fd6130 commented Jun 21, 2022

There are no other way to disable the FK constraint in doctrine:fixtures:load command when you want to refresh the database, so have to use this way instead:

From #50

php bin/console doctrine:schema:drop --force
php bin/console doctrine:schema:update --force
php bin/console doctrine:fixtures:load

@bobvandevijver
Copy link

Depending on you database, you could try the truncate flag. However, if it causes an implicit flush for the transaction, you will be out of luck with that method on PHP 8.

I've solved this issue by using a custom purger, basically as described here: https://stackoverflow.com/questions/64570346/doctrine-fixtures-how-to-override-the-purger-class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants