首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >notifications_on_conversation_id不存在mailboxer rails问题

notifications_on_conversation_id不存在mailboxer rails问题
EN

Stack Overflow用户
提问于 2014-07-07 13:21:08
回答 1查看 189关注 0票数 0

我升级了mailboxer gem,并按照文档中的步骤从0.11升级到0.12:

代码语言:javascript
复制
$ rails generate mailboxer:namespacing_compatibility
    create  db/migrate/20140707050845_mailboxer_namespacing_compatibility.rb
$ rails generate mailboxer:install -s
    skip  config/initializers/mailboxer.rb
    Copied migration 20140707050855_add_conversation_optout.mailboxer_engine.rb from mailboxer_engine

然后当我试着

代码语言:javascript
复制
$ rake db:migrate

它给了我一个错误

代码语言:javascript
复制
PG::UndefinedTable: ERROR:  relation "notifications_on_conversation_id" does not exist

有什么建议这是什么意思?该如何修复呢?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2014-10-09 03:51:00

我在从mailboxer 0.9.0升级到0.12.4 (在rails 3.2.19上)时遇到了同样的问题。

我所做的是手动编辑由namespacing_compatibility生成器创建的迁移,如下所示:

  • 在向上迁移中,我在rename_index命令中使用"index_“作为"from”索引名称的前缀。
  • 在向下迁移中,我同样将" to“索引名称重命名。
  • 在向下迁移中,我还发现我需要将update_all命令移到开头,放在rename_table命令之前。H210F211

我编辑后的迁移结果是这样的。在这里,我用注释起诉了编辑过的行。

代码语言:javascript
复制
class MailboxerNamespacingCompatibility < ActiveRecord::Migration

  def self.up
    rename_table :conversations, :mailboxer_conversations
    rename_table :notifications, :mailboxer_notifications
    rename_table :receipts,      :mailboxer_receipts

    if Rails.version < '4'
      # i edited the next two lines by adding the index_ prefix
      rename_index :mailboxer_notifications, :index_notifications_on_conversation_id, :mailboxer_notifications_on_conversation_id 
      rename_index :mailboxer_receipts,      :index_receipts_on_notification_id,      :mailboxer_receipts_on_notification_id 
    end

    Mailboxer::Notification.where(type: 'Message').update_all(type: 'Mailboxer::Message')
  end

  def self.down
    # i moved this line from the end of the down block to here
    Mailboxer::Notification.where(type: 'Mailboxer::Message').update_all(type: 'Message')

    rename_table :mailboxer_conversations, :conversations
    rename_table :mailboxer_notifications, :notifications
    rename_table :mailboxer_receipts,      :receipts

    if Rails.version < '4'
      # i edited the next two lines by adding the index_ prefix
      rename_index :notifications, :mailboxer_notifications_on_conversation_id, :index_notifications_on_conversation_id
      rename_index :receipts,      :mailboxer_receipts_on_notification_id,      :index_receipts_on_notification_id
    end
  end
end

然后,我运行迁移,运行另一个(mailboxer:install)生成器,并运行该迁移。到目前为止,情况似乎还不错。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24603483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档