You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint (hng_boilerplate.category_product, CONSTRAINT category_product_category_id_foreign) (Connection: mysql, SQL: truncate table categories)
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:
idehen-divine
changed the title
[FIX][php]:ArticlesTableSeeder issue on php artisan db:seed
[fix][php]: Disable Foreign Key Checks during truncating before running database seeding
Feb 28, 2025
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
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: