MySQL 错误 #1054 - “字段列表”中的未知列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19212894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:04:00  来源:igfitidea点击:

MySQL error #1054 - Unknown column in 'Field List'

mysqlmysql-error-1054

提问by user2852418

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.

每当我尝试将数据输入到我的 tblorder 时,我都会收到错误消息 #1054 - “字段列表”中的未知列“FK_Customer_ID”。我尝试分解我的代码,在这样做时,我发现 FK_Customer_ID 和 OrderQuantity 重复出现错误,而 FK_DVD_ID 它将采用单个数据条目。我尝试删除表并重新创建它,我删除了数据库并重新创建了它,但没有任何效果。据我所知,我的代码和拼写都是正确的,所以我真的被卡住了。

My tblorder is-

我的 tblorder 是-

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 -

FK_Customer_ID 正在寻址 -

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 -

FK_DVD_ID 正在寻址 -

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!

任何修复问题的帮助将不胜感激,因为它将帮助我完成 A2 计算课程!

回答by Salem

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

您的 OrderQuantity 列中有错误。它在 INSERT 语句中命名为“OrderQuantity”,在表定义中命名为“OrderQantity”。

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

另外,我认为您不能NOW()在 OrderDate 中用作默认值。尝试使用以下内容:

 OrderDate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

Example Fiddle

示例小提琴

回答by Lealo

I had this error aswell.

我也有这个错误。

I am working in mysql workbench. When giving the values they have to be inside "". That solved it for me.

我在 mysql 工作台工作。当给出值时,它们必须在“”内。那为我解决了。