从4.2.10升级到Rails 5.2.2后出现此错误。
我正在使用activerecord-postgis-adapter来放置模型。
现在,由于某些错误的SQL,我收到此错误。
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "location"
LINE 1: ..."locatable_type" = $1 WHERE "users"."id" = $2 AND "location"...
^
: SELECT "users"."id" AS t0_r0, "users"."username" AS t0_r1, "users"."created_at" AS t0_r2, ..., FROM "users" LEFT OUTER JOIN "locations" ON "locations"."locatable_id" = "users"."id" AND "locations"."locatable_type" = $1 WHERE "users"."id" = $2 AND "location"."locatable_type" = $3 LIMIT $4
from /Users/user/.rvm/gems/ruby-2.3.1/gems/activerecord-5.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:611:in `async_exec_params'
Caused by PG::UndefinedTable: ERROR: missing FROM-clause entry for table "location"
LINE 1: ..."locatable_type" = $1 WHERE "users"."id" = $2 AND "location"...
问题是,没有location
表,而我要做的就是使用Location.create(:locatable_type => "User", :locatable_id => id, :point => "POINT(0 0)")
创建记录
就像忘记了位置模型名称的复数形式。