Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unknown column in 'field list'", but column does exist

DROP TABLE IF EXISTS `transactions`; CREATE TABLE `transactions` (   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,   `purchase_date` datetime DEFAULT NULL,   PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `transactions` (`purchase_date`) VALUES (NULL) 

I've isolated my problem in this code. When I run it, I get the error:

[ERROR in query 3] Unknown column 'purchase_date' in 'field list'

Anyone an idea?

like image 836
Rits Avatar asked Apr 13 '13 15:04

Rits


People also ask

How do you fix Unknown column in field list?

To fix the error above, simply add a quotation mark around the value. You can use both single quotes or double quotes as shown below: INSERT INTO users(username, display_name) VALUES ("jackolantern", 'Jack'); Now the INSERT statement should run without any error.

Why is there an unknown column in the field list?

The MySQL unknown column in field list error happens when you put a column name in your SQL script that can't be found by MySQL. The error above is because there's no student_name column in the students table.

What does column in field list is ambiguous?

You may see an error that says something like Column 'id' in field list is ambiguous . This error means that there is a field name that is present in more than one table, so it needs to be scoped with the table name to avoid ambiguity: using orders.id instead of just id will resolve the issue.

What is the field list in SQL?

The field-list portion of a SQL*Loader control file provides information about fields being loaded, such as position, datatype, conditions, and delimiters.


2 Answers

There is an unprintable character 30 (RecordSeparator) inserted between purchase_date and the ' in the INSERT statement. Just remove the text ('purchase_date') and rewrite it by hand it should be fine.

like image 118
whetstone Avatar answered Oct 07 '22 08:10

whetstone


Nery niche solution when I got this error.

I had a BEFORE INSERT trigger on my table that did something with NEW.`field_mysql_doesnt_think_exists` and if I didn't pass that field to an insert statement then I would get

[ERROR in query 3] Unknown column 'field_mysql_doesnt_think_exists' in 'field list'

like image 21
Lewis Avatar answered Oct 07 '22 10:10

Lewis