試圖做一個簡單的插入語句,但得到一個外鍵關係錯誤。試圖進入聲明錯誤
insert into orders (userId, orderDate, shippingDate)
values('xyz123', now(), now());
我得到的錯誤是 「不能添加或更新子行,外鍵約束失敗(「example_1010 .
訂單,CONSTRAINT
orders_ibfk1 FOREIGN KEY (
用戶id ) REFERENCES
用戶(
userid`))」
我認爲我需要使用「in clause」來繞過約束,但我認爲我沒有正確使用它。
insert into orders (userId, orderDate, shippingDate)
values('xyz123', now(), now())
in (select userId from users);
正如錯誤中明確規定的建議,你不能插入users表中不存在的'userId'。 – e4c5
嘗試在用戶表中已經存在相同的userId。 – siddaramesh