Cannot truncate a table referenced by a FOREIGN KEY constraint
TRUNCATE is refused because another table has a foreign key pointing to it.
Cannot truncate table because it is being referenced by a FOREIGN KEY constraintCannot truncate a table referenced in a foreign key constraintTRUNCATE referenced by foreign keytruncate table cannot be truncated FOREIGN KEY CASCADEERROR 1701 Cannot truncate a table referenced in a foreign key constraint Meaning
Unlike DELETE, TRUNCATE can't run when foreign keys reference the table (SQL Server error 4712, MySQL 1701, PostgreSQL needs CASCADE). Delete child rows first, use TRUNCATE ... CASCADE (PostgreSQL), disable/drop the constraints temporarily, or use DELETE.
Common causes
- Child table with FK to the table
- Truncating in the wrong order
- Constraint not dropped first
- Trying to reset test data
- Self-referencing foreign key
⚡ Quick fix
- Truncate/delete the child tables first
- PostgreSQL:
TRUNCATE parent CASCADE - Temporarily drop the FK, truncate, re-add it
Detailed fix by platform
SQL
TRUNCATE TABLE orders, order_items RESTART IDENTITY CASCADE; -- PostgreSQL
How to diagnose
- Referencing tables — Which?
- Order — Children first?
- CASCADE — Acceptable?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in SQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026