“Unknown column in 'field list'”, but column does exist

后端 未结 9 1361
既然无缘
既然无缘 2020-12-06 04:41
DROP TABLE IF EXISTS `transactions`;
CREATE TABLE `transactions` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `purchase_date` datetime DEFAULT NULL,
  PRIMAR         


        
相关标签:
9条回答
  • 2020-12-06 05:36

    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'

    0 讨论(0)
  • 2020-12-06 05:38

    Same error in a different scenario:

    This also happens when you miss @ symbol for a variable.

    SET @myVar1=1;  SELECT @myVar1;  -- GOOD, correctly prints:  1
    SET @myVar1=1;  SELECT  myVar1;  -- BAD, prints:  Unknown column 'myVar1' in 'field list' 
    
    0 讨论(0)
  • 2020-12-06 05:40

    I just spent the better part of a day figuring this out. My problem was the same: invisible characters kiboshing the query and returning the "unknown column" error.

    I solved it by wading back into Windows and removing the garbage using NotePad++.

    How did the garbage get in there in the first place? I think it was because I made the mistake of copying some long complex queries into LibreOffice Writer (my functional specs document) instead of just bookmarking them in phpMyAdmin or saving them in a text editor. Pasting them from LibreOffice into the query window is where (I think) the garbage originated.

    Once there, it persisted like Malaria. I couldn't even get rid of it by hand-retyping the whole query -- I had to put it into NotePad++ (Encoding menu) and show ANSI and the UTF8 combos and then remove the garbage by hand.

    Once that was done, the query worked.

    0 讨论(0)
提交回复
热议问题