SQL错误:1364字段'XXXX'没有默认值1

时间:2016-12-09 16:08:26

标签: mysql sql

我有桌子ROUTE

CREATE TABLE ROUTE (
RouteID INTEGER(4) AUTO_INCREMENT,
RouteName VARCHAR (50) NOT NULL,
BoardingStop VARCHAR (50) NOT NULL,
AlightingStop VARCHAR (50) NOT NULL,
PRIMARY KEY (RouteID )
);

还有第二张表CUSTOMER

CREATE TABLE CUSTOMER (
CustomerID INTEGER(4) PRIMARY KEY,
CustomerName VARCHAR(50) NOT NULL,
CustomerAge VARCHAR(50) NOT NULL,
Address VARCHAR (50) NOT NULL,
RouteID INTEGER(4) NOT NULL,
FOREIGN KEY (RouteID) REFERENCES ROUTE(RouteID)
);

当我将数据插入customerID

INSERT INTO `CUSTOMER` (`CustomerID`,`CustomerName`,`CustomerAge`,`Address`) VALUES (1,"Madeline Shepard",17,"Ap #303-5324 Nunc St.");

我得到了错误

  

错误代码:1364。字段'RouteID'没有默认值

帮助

如何修复它。

1 个答案:

答案 0 :(得分:1)

不确定teachers_id_teacher的来源,但错误文字对于您提供的插入声明似乎是准确的。

您的字段RouteID是"必需" (如NOT NULL所示),但您已从INSERT中删除了它。

由于您还没有提供值且它没有默认值,因此插入操作将失败。为此字段设置默认值,或指定值:

INSERT INTO `CUSTOMER` (`CustomerID`,`CustomerName`,`CustomerAge`,`Address`, `RouteID`) VALUES (1,"Madeline Shepard",17,"Ap #303-5324 Nunc St.", 1234);