I got error “The DELETE statement conflicted with the REFERENCE constraint”

前端 未结 4 734
醉酒成梦
醉酒成梦 2020-12-01 23:08

I tried to truncate a table with foreign keys and got the message:

\"Cannot truncate table because it is being referenced by a FOREIGN KEY co

4条回答
  •  执念已碎
    2020-12-01 23:48

    You are trying to delete a row that is referenced by another row (possibly in another table).

    You need to delete that row first (or at least re-set its foreign key to something else), otherwise you’d end up with a row that references a non-existing row. The database forbids that.

提交回复
热议问题