-
Notifications
You must be signed in to change notification settings - Fork 64
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
[fix][php]: Disable Foreign Key Checks during truncating before running database seeding #626
Comments
The solution isn't removing FK checks, its ensuring the category needed is first created in the categories table before creating them in category_product |
@bhimbho here we are truncating the tables before seeding, now it's not only the category_product that has the issue all tables that ref a foreign id has it ![]() this was my solution |
and this is done directly on database seeder solving all the recurring issues on all seeders try recreating the error with
|
Modified DatabaseSeeder.php to temporarily disable foreign key checksbefore truncating tables, ensuring smooth database seeding without constraint violations. Fixes hngprojects#626
Modified DatabaseSeeder.php to temporarily disable foreign key checksbefore truncating tables, ensuring smooth database seeding without constraint violations. Fixes hngprojects#626
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint (
hng_boilerplate
.category_product
, CONSTRAINTcategory_product_category_id_foreign
) (Connection: mysql, SQL: truncate tablecategories
)This error occurs because the categories table is referenced by the category_product table through a foreign key constraint. MySQL prevents truncating tables when they have foreign key constraints.
the solutions is to Disable Foreign Key Checks when seeding
The text was updated successfully, but these errors were encountered: