how to fix error #1054 unknown column in field

2019-05-06 20:04发布

This is my table.

create table Property(
p_id int(4) null primary key,
p_address varchar(120) not null,
c_id int(4) not null,
foreign key (c_id) references customer (c_id)
);


insert into Property values
('2001','Elm_House_11_Short_Lane_Hertfordshire_H5_667',’3001’);

insert into Property values 
('2002','Jainlight_House_Apple_Lane_Kent_K7_988',’3002’);

insert into Property values
('2003','Excelsior_House_23_Oracle_Centre_Reading',’3003’);

insert into Property values ('2004','27_Wroxton_Road_London_SE15',’3004’);

I'm keep getting an unknown column error when entering this data.

2条回答
一纸荒年 Trace。
2楼-- · 2019-05-06 20:37

remove the quotes and backticks when you insert int values:

insert into Property values
(2001,'Elm_House_11_Short_Lane_Hertfordshire_H5_667',3001);

insert into Property values 
(2002,'Jainlight_House_Apple_Lane_Kent_K7_988',3002);

insert into Property values
(2003,'Excelsior_House_23_Oracle_Centre_Reading',3003);

insert into Property values (2004,'27_Wroxton_Road_London_SE15',3004);

Quotes are only needed, when you working with char fields and backticks are escape characters for table or column names.

查看更多
别忘想泡老子
3楼-- · 2019-05-06 21:03

I got this error exporting from MariaDb and then importing into MySql. It concerned a field that I had recently added and for which I hadn't added values yet - so in all records this field was empty. When I added a few values for this field the error disappeared.

查看更多
登录 后发表回答