我目前正在寻找将大量虚拟信息输入到我创建的数据库中。
这是其中一张表:
SET foreign_key_checks = 0;
CREATE TABLE Staff
(
Staff_ID INTEGER(5) PRIMARY KEY AUTO_INCREMENT,
Local_ID INTEGER(5),
First_name VARCHAR(20) NOT NULL,
Last_name VARCHAR(20) NOT NULL,
Email VARCHAR(30) NOT NULL,
Telephone INTEGER(15) NOT NULL,
Date_employed DATE NOT NULL,
Salary DECIMAL NOT NULL,
Sales_ID INTEGER(5),
Manager_ID INTEGER(5),
Development_ID INTEGER(5),
FOREIGN KEY (Local_ID) REFERENCES LocalOffice(Local_ID),
FOREIGN KEY (Sales_ID) REFERENCES Sales_Advisors(Sales_ID),
FOREIGN KEY (Manager_ID) REFERENCES Site_Manager(Manager_ID),
FOREIGN KEY (Development_ID) REFERENCES Development(Development_ID)
);
SET foreign_key_checks = 1;
这是我提交数据的唯一方法:
INSERT INTO Staff VALUES
(null, null, 'Sean', 'D', 'UP62@mac.uk', '07411557877', '2012-10-08', 80000.00,null,null,null);
如果我尝试输入 int 值:我得到:
INSERT INTO Staff VALUES
(null,1, 'Luke', 'Clifford', 'UP624715@myport.ac.uk', '07411557077', '2012-10-08', 80000.00,1,1,1);
错误:
#1452 - 无法添加或更新子行:外键约束失败(`happy_homes`.`staff`,CONSTRAINT `staff_ibfk_1` FOREIGN KEY (`Local_ID`) 参考 `localoffice` (`Local_ID`))
谁能帮忙