MySQL错误#1054-“字段列表"中的未知列 [英] MySQL error #1054 - Unknown column in 'Field List'

查看:582
本文介绍了MySQL错误#1054-“字段列表"中的未知列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试将数据输入到我的tblorder中时,我都会收到错误消息#1054-字段列表"中的未知列"FK_Customer_ID". 我尝试分解我的代码,然后执行此操作,发现对FK_Customer_ID和OrderQuantity重复该错误,而FK_DVD_ID将仅接受单个数据条目.我尝试删除该表并重新创建它,我删除了该数据库并重新创建了它,但是没有任何效果.据我所知,我的代码和拼写是正确的,所以我真的很困惑.

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.

我的名字是-

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)
);

我要输入的数据是-

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正在寻址-

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正在寻址-

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)
);

在解决此问题方面的任何帮助将不胜感激,因为它将帮助我完成A2计算课程!

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

推荐答案

您的OrderQuantity列中有错误.在INSERT语句中将其命名为"OrderQuantity",在表定义中将其命名为"OrderQantity".

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

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

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

小提琴示例

这篇关于MySQL错误#1054-“字段列表"中的未知列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆