我看到多个表抛出此错误。搜索StackOverflow似乎大多数人的问题都与特定的列缺失相关,但在我的情况下,它试图选择所有内容,即。使用" *"。
任何人都有见解?
Mysql2::Error: Unknown column 'users.*' in 'field list'
更新
从rails log:
Mysql2::Error: Unknown column 'users.*' in 'field list': SELECT `users`.`*` FROM `users` WHERE `users`.`id` = 53 ORDER BY `users`.`id` ASC LIMIT 1
我想出了如何在本地重现这一点,或者至少我认为它可能会如何重现:
2.1.2 :037 > client = Mysql2::Client.new(:host => "localhost", :username => "root", :password => "root", :database => "development")
=> #<Mysql2::Client:0x007ff45b72dd30 @read_timeout=nil, @query_options={:as=>:hash, :async=>false, :cast_booleans=>false, :symbolize_keys=>false, :database_timezone=>:local, :application_timezone=>nil, :cache_rows=>true, :connect_flags=>2147525125, :cast=>true, :host=>"localhost", :username=>"root", :password=>"root", :database=>"development"}>
2.1.2 :038 > result = client.query("SELECT `users`.`*` FROM `users` LIMIT 1")
Mysql2::Error: Unknown column 'users.*' in 'field list'
from (irb):40:in `query'
from (irb):40
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/console.rb:90:in `start'
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/console.rb:9:in `start'
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
查询:
SELECT `users`.`*` FROM `users` LIMIT 1
当特殊的所有选择器*用引号括起来时,失败。
SELECT `users`.* FROM `users` LIMIT 1
没有问题。也许这是一个MySQL的东西?无论如何,这些查询都是由ActiveRecord / ActiveModel生成的,所以我可能发现了一个错误。