mysql错误代码1054,MySQL错误#1054-“字段列表”中的未知列
发布日期:2021-11-18 06:42:32 浏览次数:2 分类:技术文章

本文共 1932 字,大约阅读时间需要 6 分钟。

Whenever I try to input data into my tblorder I get the error message #1054 - Unknown column 'FK_Customer_ID' in 'field list'.

I have tried breaking my code down and in doing this I found that the error is repeated for FK_Customer_ID and OrderQuantity whereas FK_DVD_ID it will take single data entries. I have tried dropping the table and recreating it, I have dropped the database and recreated it but nothing works. As far as I can tell my code is correct along with my spelling so I'm really stuck.

My tblorder is-

CREATE TABLE tblorder

(

Order_ID INT AUTO_INCREMENT NOT NULL,

FK_Customer_ID INT NOT NULL,

FK_DVD_ID INT NOT NULL,

OrderDate DATETIME NOT NULL DEFAULT NOW(),

OrderQantity INT NOT NULL,

PRIMARY KEY (Order_ID),

FOREIGN KEY (FK_Customer_ID) REFERENCES tblcustomer (Customer_ID),

FOREIGN KEY (FK_DVD_ID) REFERENCES tbldvd (PK_ID)

);

The data I am trying to put in is-

INSERT INTO tblorder

(FK_Customer_ID, FK_DVD_ID, OrderQuantity)

VALUES

(1, 3, 2),

(1, 5, 1),

(1, 10, 4),

(1, 15, 3),

(2, 5, 4),

(2, 17, 3),

(3, 15, 1),

(3, 16, 1),

(3, 17, 1);

FK_Customer_ID is addressing -

CREATE TABLE tblcustomer

(

Customer_ID INT AUTO_INCREMENT NOT NULL,

FirstName VARCHAR(50) NOT NULL,

LastName VARCHAR(50) NOT NULL,

Age INT NOT NULL,

PRIMARY KEY (Customer_ID)

);

FK_DVD_ID is addressing -

CREATE TABLE tblDVD

(

PK_ID INT AUTO_INCREMENT NOT NULL,

Title VARCHAR(100) NOT NULL,

DIrector VARCHAR(100) NOT NULL,

Genre VARCHAR(40) NOT NULL,

dvd_Year YEAR NOT NULL,

Price FLOAT(2) NOT NULL,

Quantity INT NOT NULL,

PRIMARY KEY (PK_ID)

);

Any help in fixing the will be greatly appreciated as it will help me with my A2 computing lesson!

解决方案

You have an error in your OrderQuantity column. It is named "OrderQuantity" in the INSERT statement and "OrderQantity" in the table definition.

Also, I don't think you can use NOW() as default value in OrderDate. Try to use the following:

OrderDate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

转载地址:https://blog.csdn.net/weixin_33648352/article/details/118818287 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:微型计算机ROM和RAM,4微机中ROM和RAM的区别是什么
下一篇:gitlab 构建tag,GitLab CI-添加标签时避免构建

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年03月21日 22时27分50秒