[英]Deleting rows from 3 tables in MySQL table
我有3個表(我僅提及所需的屬性):
進口 id
, date
import_head id
, import_id
import_body id
, import_head_id
import_head
和import_body
創建一個導入項目,導入是由數十個導入項目創建的。關系: import 1 <==> N * import_head * 1 <==> 1 * import_body *(每個關系上的DELETE CASCADE)
從導入表中刪除行時如何刪除所有導入項?
使用DELETE FROM import WHERE id = ?
刪除導入時 引發錯誤: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails
-在import_head_id
在此先多謝
修改子表上的外鍵並在刪除時進行(CASCADE)
這應該為你工作
我已經更改了數據庫中的實體,所以現在只有兩個表:
import
import_item
我沒有發現更好的方法,但是它可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.