无法在rails 5控制台中选择记录

时间:2016-11-10 16:03:36

标签: ruby-on-rails heroku

我已经在c9.io上测试了新的rails代码,并且当邀请表上的emailReceived字段为false时,它可以正常选择记录,

在我将新代码更新为Heroku之后,它没有成功。并显示错误消息。

  

ActiveRecord :: StatementInvalid:PG :: UndefinedColumn:ERROR:列   “emailreceived”不存在

我使用了Invitation.column_names,可以找到“emailReceived”。数据库是否已损坏?以下是控制台信息供您参考。请帮忙建议如何解决它。

irb(main):005:0> Invitation.column_names
=> ["id", "church", "telephone1", "telephone2", "worshipTime", "contactName", "contactNumber", "priest", "preacher", "emailReceived", "acceptPromote", "promotionTime", "other", "created_at", "updated_at"]
irb(main):006:0> Invitation.where("emailReceived = false")
Invitation Load (3.0ms) SELECT "invitations".* FROM "invitations" WHERE (emailReceived = false)
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "emailreceived" does not exist
LINE 1: SELECT "invitations".* FROM "invitations" WHERE (emailReceiv...
^
HINT: Perhaps you meant to reference the column "invitations.emailReceived".
: SELECT "invitations".* FROM "invitations" WHERE (emailReceived = false)
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in async_exec'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:598:inblock in exec_no_cache'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:566:in block in log'
from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/notifications/instrumenter.rb:21:ininstrument'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:560:in log'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:598:inexec_no_cache'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:585:in execute_and_clear'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:103:inexec_query'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:373:in select'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:41:inselect_all'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in select_all'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/querying.rb:39:infind_by_sql'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:699:in exec_queries'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:580:inload'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:260:in records'
from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:683:ininspect'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in start'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:instart'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in console'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:inrun_command!'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in <top (required)>'
from bin/rails:8:inrequire'
from bin/rails:8:in `'irb(main):007:0>

关于这个案例的另外一个信息,我运行“heroku run rake --trace db:migrate VERSION = 20161007083159”并得到以下结果。它仍然无效

heroku run rake --trace db:migrate VERSION=20161007083159
Running rake --trace db:migrate VERSION=20161007083159 on ⬢ shrouded-scrubland-30708... up, run.1694
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
  ActiveRecord::SchemaMigration Load (0.6ms)  SELECT "schema_migrations".* FROM "schema_migrations"
  ActiveRecord::SchemaMigration Load (0.5ms)  SELECT "schema_migrations".* FROM "schema_migrations"
   (0.5ms)  SELECT pg_try_advisory_lock(129277373589159705);
  ActiveRecord::SchemaMigration Load (0.5ms)  SELECT "schema_migrations".* FROM "schema_migrations"
  ActiveRecord::InternalMetadata Load (0.8ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2  [["key", :environment], ["LIMIT", 1]]
   (0.5ms)  BEGIN
   (0.4ms)  COMMIT
   (0.5ms)  SELECT pg_advisory_unlock(129277373589159705)
** Invoke db:_dump (first_time)
** Execute db:_dump

由于

Patrick Lee

1 个答案:

答案 0 :(得分:0)

最终,我发现问题是由于postgresql的大小写敏感而发生的。所以我在模型上将代码从Invitation.where("emailReceived is ? OR emailReceived = ?", nil,false)更改为Invitation.where("emailReceived" => nil)

但还有一个问题,如何对Invitation.where("emailReceived" => nil) Invitation.where("emailReceived" => false)使用OR?

由于

Patrick Lee