Ruby on rails 外国人-删除外键

Ruby on rails 外国人-删除外键,ruby-on-rails,psql,mailboxer,foreigner,Ruby On Rails,Psql,Mailboxer,Foreigner,我正在尝试在rails 4应用程序中使用mailboxer。当我尝试部署db时,出现了一个问题。创建mailboxer conversations表时出错,该表在notifications表中具有依赖项 我正在尝试删除通知会话的外键 我创建了一个迁移,它说: change_table :notifications do |t| t.remove_foreign_key :conversations 但是,rake中止并表示外键不存在 rake aborted! An error has occ

我正在尝试在rails 4应用程序中使用mailboxer。当我尝试部署db时,出现了一个问题。创建mailboxer conversations表时出错,该表在notifications表中具有依赖项

我正在尝试删除通知会话的外键

我创建了一个迁移,它说:

change_table :notifications do |t|
t.remove_foreign_key :conversations
但是,rake中止并表示外键不存在

rake aborted!
An error has occurred, this and all later migrations canceled:

PG::UndefinedObject: ERROR:  constraint "notifications_conversation_id_fk" of relation      "notifications" does not exist
我的模式包括: 添加外键“通知”、“对话”,名称:“对话id上的通知”

我试图在创建mailboxer的原始迁移中rake db:migrate:down,但也出现了一个错误,即“找不到命令”


有人能帮忙吗?谢谢。

架构中的
add\u foreign\u key
命令为您的外键提供了名称
notifications\u on\u conversation\u id
。此名称不同于外国人通常基于列名指定的默认名称,即
notifications\u conversation\u id\u fk
。因此,
remove\u foreign\u key
命令必须指定现有的外键名,而不是列名。尝试:

remove_foreign_key :notifications, name: "notifications_on_conversation_id"
官方文件:

当我运行时,我得到:

NoMethodError:未定义的方法“删除外键”#
你是说?删除索引
智慧之言-外键永远不要使用id整数以外的任何东西。我在一个假的应用程序上练习时使用了一个title param,它会导致:

ActiveRecord::AssociationTypeMismatch(公司(#70210936585940)应为,获得了作为字符串(#70210933923380)实例的“公司4”)

手动删除显示错误的上次创建的迁移,并突出rn
rake db:rollback
以恢复到上次的第二次迁移。自这次迁移以来,我创建了许多迁移。我尝试使用时间戳引用将:向下迁移,但命令失败。
外键不存在
错误可能是因为您可能没有在模型中定义模型关系。。这也可能对您有所帮助。。谢谢。我尝试在rails迁移中取消注释创建mailboxer外键的行以及这些表之间的id链接,然后我尝试重置和迁移,然后删除、创建和迁移数据库,该数据库现在已注释掉这些外键行。在每种情况下,模式都不会更新,模式中存在外键的引用仍然存在。Mailboxer没有为这些对象创建模型,只是迁移。真奇怪。但我还是有这个问题。非常感谢。在我注释掉mailboxer迁移中的外键属性之后,我最终删除了我的DB并重新创建了它。这次我不能使用这个建议,但如果其他人也有同样的问题的话,这可能就是诀窍。谢谢,它没有回答这个问题。如果您想在另一个答案中指出问题,请在下面进行评论:)
# Removes the given foreign key from the table.
# Removes the foreign key on +accounts.branch_id+.
remove_foreign_key :accounts, :branches

# Removes the foreign key on +accounts.owner_id+.
remove_foreign_key :accounts, column: :owner_id

# Removes the foreign key named +special_fk_name+ on the +accounts+ table.
remove_foreign_key :accounts, name: :special_fk_name