how to fix error #1054 unknown column in field

Lenroy D Chandler picture Lenroy D Chandler · Jan 21, 2015 · Viewed 52.5k times · Source

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.

Answer

Jens picture Jens · Jan 21, 2015

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.