0
我有這個表:添加外鍵外鍵約束表
報價
+---------------------+-----------------------+------+-----+---------+---+
| Field | Type | Null | Key | Default
+---------------------+-----------------------+------+-----+---------+---+
| id | int(11) unsigned | NO | PRI | NULL
... (More Columns)
+---------------------+-----------------------+------+-----+-------------+
quotesPackagesInfo
+---------------+---------------------+------+-----+---------+------------+
| Field | Type | Null | Key | Default
+---------------+---------------------+------+-----+---------+------------+
| id | int(11) unsigned | NO | PRI | NULL
| quoteId | int(11) unsigned | NO | | NULL
... (More Columns)
+---------------+---------------------+------+-----+---------+------------+
quotesFlightsInfo
+---------------------------+---------------------+------+-----+----------+
| Field | Type | Null | Key | Default
+---------------------------+---------------------+------+-----+----------+
| id | int(11) unsigned | NO | PRI | NULL
| quoteId | int(11) unsigned | NO | MUL | NULL
| packageId | int(11) unsigned | YES | MUL | NULL ... (More Columns)
+---------------------------+---------------------+------+-----+----------+
所以基本上是行情whic h是主要關鍵,因爲報價中有包裹,並且包裹可以包含航班,所以我需要在包裹被刪除時,所有與該航班相關的航班都將被刪除,所以我向航班添加了一個外鍵,如下所示:
ALTER TABLE quotesFlightsInfo
ADD CONSTRAINT fk_quotesFlightsInfo_packageId
FOREIGN KEY (packageId) REFERENCES quotesPackagesInfo(id)
ON DELETE CASCADE
現在我試着去一個外鍵添加到包,這樣當報價被刪除也包刪除等的航班但是,這不是工作:(這裏查詢:
ALTER TABLE quotesPackagesInfo
ADD CONSTRAINT fk_quotesPackagesInfo_quoteId
FOREIGN KEY (quoteId) REFERENCES quotes(id)
ON DELETE CASCADE
錯誤:無法添加或更新子行:外鍵約束失敗(??????????
。 #sql-312_2
,約束fk_quotesPackagesInfo_quoteId
外鍵(quoteId
)參考文獻quotes
(id
)ON DELETE CASCADE)
那麼,表中包含什麼?另外,閱讀官方文檔中關於FK限制的章節,包括如何獲取更多信息。另請閱讀[mcve]並採取行動。 – philipxy