大家好,我正在尝试删除一条记录。但是由于外键约束而不允许我
我尝试执行的操作是 (所有卡号都是假的)
DELETE FROM payment_method
WHERE card_no = 42218345;
表结构:
CREATE TABLE payment_details (
card_no int(8) NOT NULL,
customer_id int(50) NOT NULL AUTO_INCREMENT,
CVV int(3) NOT NULL,
card_type ENUM ('Visa', 'Amex', 'American Express', 'Mastercard') NOT NULL,
expiry_date DATE NOT NULL,
PRIMARY KEY(card_no),
KEY customer_idfk1 (customer_id),
CONSTRAINT customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
和
CREATE TABLE customers (
customer_id int(50) NOT NULL AUTO_INCREMENT,
fname varchar(20) NOT NULL,
lname varchar(20) NOT NULL,
dateOfBirth date NOT NULL,
address varchar(30) NOT NULL,
city varchar(20) NOT NULL,
county ENUM('Armagh','Carlow','Cavan','Clare','Cork','Derry','Donegal','Down','Dublin','Fermanagh','Galway','Kerry','Kildare','Kilkenny','Laois','Leitrim','Limerick','Longford','Louth','Mayo','Meath','Monaghan','Offaly','Roscommon','Sligo','Tipperary','Tyrone','Waterford','Westmeath','Wexford','Wicklow') NOT NULL,
phone int(10) NOT NULL,
email varchar(20) NOT NULL,
payment_method ENUM ('Visa', 'Amex', 'Cash', 'American Express', 'Mastercard') NOT NULL,
valid_licence varchar(5) NOT NULL,
status varchar(10),
PRIMARY KEY (customer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
错误是:
1451-无法删除或更新父行:外键约束失败(
g00337857abu
。payment_details
,CONSTRAINTcustomer_idfk1
外键(
customer_id
)参考customers
(customer_id
))
有人知道为什么它不允许我删除此记录。
发现了第一个错误
现在我正尝试从客户表中删除
DELETE FROM customers
WHERE customer_id = 1
错误-#1451-无法删除或更新父行:外键 约束失败(
g00337857abu
。payment_details
,约束customer_idfk1
外键(customer_id
)参考customers
(customer_id
)