ruby-on-rails - Upgrading to Rails 5.2, can't boot, ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation does not exist
问题描述
With a new database, running bundle exec rails db:structure:load
or rails db:create
or rails db:migrate
or bin/rails db:setup
throws
rails aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "clients"
does not exist
LINE 8: WHERE a.attrelid = '"clients"'::regclass
...etc ^
I'd be happy just knowing how to debug this. At some point, some code is calling the Client model, but it's invisible. What could be requiring the clients table to exist pre-boot?
Edits:
No migrations erased, no. The app boots fine locally where there's a database: this first occurs in CI where it's booting from scratch.
Here's the stacktrace https://gist.github.com/EmmaB/01a9322ab66f258a5ebd6883a441251f showing another missing table after I commented out the following code in a Flipper initializer:
Client::Identifiers::IDENTIFER_ID_MAPPING.each do |client_identifier, client_id|
Flipper.register(client_identifier) do |actor|
actor&.client_id == client_id
end
end
But that initialiser code shouldn't run in boot when you're loading the structure, right? And indeed doesn't run in Rails 4.2.10 (upgrading from that to 5.2).
解决方案
在初始化器中包装模型调用
Rails.configuration.after_initialize do
# Model calls
end
让应用程序启动。初始化程序必须在启动过程中比在 Rails 4 中更早地调用。编辑:事实上,这里是线程https://github.com/rails/rails/issues/32870
推荐阅读
- python - python列表中是否有任何函数可以将逗号分隔值转换为单个元素?
- slack - 如何不在松弛中格式化表情符号?
- postgresql - 将 Microstrategy Cube 连接到 Postgres 物化视图
- python-2.7 - 如何为此元素编写定位器
- javascript - 涉及带条件数组的 Switch 语句中的案例
- android - Android 在 sdk 集成中链接
- php - 按添加时间对mysql行进行编号,然后在保留数字的同时进行排序
- ruby-on-rails - 在 rake 任务期间无法执行原始 sql 'UPDATE ...'
- javascript - 同时使用的两种排序/过滤方法 Javascript
- java - Java ArrayList 删除元素恢复浪费的空间?