我最近刚刚通过迁移添加了一个专栏到我的生产应用程序,我一整天都收到Rollbar错误,这是我无法弄清楚的。
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column callable_phone_numbers.active does not exist
LINE 1: ...llable_phone_numbers"."phone_number_id" AS t0_r3, "callable_...
^
: SELECT "callable_phone_numbers".*, "callable_phone_numbers"."id" AS t0_r0, "callable_phone_numbers"."callable_id" AS t0_r1, "callable_phone_numbers"."callable_type" AS t0_r2, "callable_phone_numbers"."phone_number_id" AS t0_r3, "callable_phone_numbers"."active" AS t0_r4, "callable_phone_numbers"."created_at" AS t0_r5, "callable_phone_numbers"."updated_at" AS t0_r6, "phone_numbers"."id" AS t1_r0, "phone_numbers"."number" AS t1_r1, "phone_numbers"."created_at" AS t1_r2, "phone_numbers"."updated_at" AS t1_r3, "phone_numbers"."label" AS t1_r4, "phone_numbers"."assigned" AS t1_r5, "phone_numbers"."account_id" AS t1_r6, "phone_numbers"."sent_messages_count" AS t1_r7, "phone_numbers"."received_messages_count" AS t1_r8, "phone_numbers"."last_sent_message_at" AS t1_r9, "phone_numbers"."last_received_message_at" AS t1_r10, "phone_numbers"."carrier_name" AS t1_r11, "phone_numbers"."carrier_type" AS t1_r12, "phone_numbers"."carrier_updated_at" AS t1_r13 FROM "callable_phone_numbers" LEFT OUTER JOIN "phone_numbers" ON "phone_numbers"."id" = "callable_phone_numbers"."phone_number_id" WHERE "phone_numbers"."disconnected" = 'f' AND "callable_phone_numbers"."callable_type" = 'Student' AND "callable_phone_numbers"."callable_id" IN (1181)
如您所见,它抱怨列callable_phone_numbers.active
不存在。我最近使用迁移从连接表中删除该列,并在表phone_numbers
上创建了一个类似的列(已断开连接)。
是的,我在制作时仔细检查了rake db:migrate
。
唯一使用.active
的地方是我的Student
模型中的关联where子句。
以前是......
class Student.rb < ActiveRecord::Base
has_many :active_phone_numbers, -> { where callable_phone_numbers: {active: true} }, through: :callable_phone_numbers, source: :phone_number
...但与迁移同时,协会变成......
class Student.rb < ActiveRecord::Base
has_many :active_phone_numbers, -> { where phone_numbers: {disconnected: false} }, through: :callable_phone_numbers, source: :phone_number
我一直无法在开发中重现此错误,并且错误似乎在生产中随机重现(加载学生一次,应用程序错误,刷新,没有错误)。
我的代码是否有可能在Heroku上的dynos中被奇怪地缓存?数据库已保存重复查询?还有什么奇怪的我不知道的?