我从邮箱 0.9.0 升级到 0.12.4(在 rails 3.2.19 上)时遇到了同样的问题。
我所做的是手动编辑namespacing_compatibility
生成器创建的迁移,如下所示:
- 在向上迁移中,我在命令中为“from”索引名称添加了“index_”前缀
rename_index
。
- 在向下迁移中,我同样重命名了“to”索引名称。
- 同样在向下迁移中,我发现我需要将命令移到
update_all
命令的开头,在rename_table
命令之前。
我编辑的迁移结果是这样的。在这里,我已经用评论指出了已编辑的行。
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) 生成器,然后运行迁移。到目前为止,事情似乎正在奏效。