ruby-on-rails - Sidekiq PG::UndefinedColumn:错误:不存在

标签 ruby-on-rails postgresql model sidekiq

我为我的 phone_contact 模型做了一个迁移,将 branch 更改为 branch_name。然后我将代码更改为:

class ContactWorker
  include Sidekiq::Worker


  def perform(record, service_type = 'test', list_type = 'test')
    phone_contact = PhoneContact.create(
        client_id: record['ClientID'],
        client_name: record['ClientName'],
        branch_id: record['branchID'],
        branch_name: record['branch'],
        unit_id: record['UnitID'],
        member_id: record['MemberID'],
        first_name: record['FirstName'],
        last_name: record['LastName'],
        date_of_birth: record['DateofBirth'],
        most_recent_join_date: record['ChangeDate'],
        old_membership_type: record['OldMembershipType'],
        membership_type: record['NewMembershipType'],
        phone_number: record['HomePhone'],
        email: record['EMailAddress'],
        visits: record['ID__Visits'],
        primary_language: record['PrimaryLanguage'],
        call_type: record['CallType'],
        list_id: "#{Time.new.strftime("%Y_%m_%d")}_#{service_type}_#{list_type}"
    )
  end
end

如您所见,branch 不再列出。它明确指出 branch_name:

所以我传入了一个record,它是一个包含上述所有属性的哈希值给这个worker。不管该散列是什么样子,这是我收到的错误:

"error_message"=>"PG::UndefinedColumn: ERROR: column \"branch\" of relation \"phone_contacts\" does not exist\nLINE 1: INSERT INTO \"phone_contacts\" (\"branch\", \"branch_id\", \"call_t...\n
^\n: INSERT INTO \"phone_contacts\" (\"branch\", \"branch_id\", \"call_type\", \"client_id\", \"client_name\", \"created_at\", \"date_of_birth\", \"email\", \"first_name\", \"last_name\", \"list_id\", \"member_id\", \"membership_type\", \"most_recent_join_date\", \"old_membership_type\", \"phone_number\", \"primary_language\", \"unit_id\", \"updated_at\", \"visits\") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) RETURNING \"id\"", "error_class"=>"ActiveRecord::StatementInvalid"

错误变成了这个,代码没有改变——我只是得到了一个unknown attribute: branch_name错误。

这可能是什么原因造成的?我的迁移运行良好,当我查看我的数据库时,我看到了 branch_name,如果我使用 Rails 控制台并手动执行我的代码正在执行的步骤,一个接一个,它工作正常。它仅在我使用 Sidekiq 时失败。我正在使用 Ruby 2.0.0 和 Rails 4.0.0。

最佳答案

我的意见是模式被缓存了。您是否尝试过重新启动所有工作人员?

关于ruby-on-rails - Sidekiq PG::UndefinedColumn:错误:不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22663633/

相关文章:

c# - 如何遍历模型以在 MVC 中找到相似的值

ruby-on-rails - 以数组作为属性的 Ruby 模型

Postgresql pgstartup.log 文件问题

python - Django,覆盖多对多字段ModelManager

postgresql - 直接使用PostgreSQL的多版本并发控制

Hibernate 如何有效地处理 100.000+ 个实体更新

model - 如何使用 jena API 和 SPARQL 更新模型,例如。更新节点值

ruby-on-rails - s3sh 命令行 ubuntu 仍然存在(EC2,s3 amazon)

mysql - 使用 MySQL 子句 "Use index(' index_name')"using ActiveRecord 的最佳方式

css - 忽略用 a 关闭 li 的尝试