我正在尝试创建一个与 Topics 表的外键关系。
问题是,在 GitHub 工作流测试环境中,测试因奇怪的原因而失败,它试图访问父表中一个早已不存在且在几年前的核心迁移中已被删除的字段!
错误是 PG::UndefinedColumn: ERROR: column topics.off_topic_count does not exist
我已确认这在测试过程中已经运行:
== 20180917024729 RemoveSuperfluousColumns: migrating =========================
== 20180917024729 RemoveSuperfluousColumns: migrated (0.0410s) ===============
我并没有以任何方式显式引用这个旧的父表字段……它似乎在自己生成 SQL……但对于当前的事物定义来说是不恰当的。
== 20231119010101 CreateLocationsTopicTable: migrating ========================rake aborted!
[12035](https://github.com/paviliondev/discourse-locations/actions/runs/7039607316/job/19158951878?pr=103#step:19:12036)StandardError: An error has occurred, this and all later migrations canceled: (StandardError)
[12036](https://github.com/paviliondev/discourse-locations/actions/runs/7039607316/job/19158951878?pr=103#step:19:12037)
[12037](https://github.com/paviliondev/discourse-locations/actions/runs/7039607316/job/19158951878?pr=103#step:19:12038)PG::UndefinedColumn: ERROR: column topics.off_topic_count does not exist
[12038](https://github.com/paviliondev/discourse-locations/actions/runs/7039607316/job/19158951878?pr=103#step:19:12039)LINE 1: ...cs"."deleted_at", "topics"."highest_post_number", "topics"...
表定义非常简单:
class CreateLocationsTopicTable < ActiveRecord::Migration[7.0]
def change
create_table :locations_topic do |t|
t.references :topic, foreign_key: true
t.float :latitude, null: false
SNIP
更奇怪的是,这个迁移在 Production 中是有效的!
欢迎任何见解!