老外-删除外键 [英] foreigner - remove foreign key
问题描述
我正在尝试在Rails 4应用程序中使用邮箱程序.当我尝试部署数据库时出现问题.创建邮箱程序对话表时发生错误,该表在通知表中具有依赖性.
I am trying to use mailboxer in my rails 4 app. A problem is arising when i try to deploy the db. The error occurs in creating the mailboxer conversations table, which has dependencies in notifications table.
我正在尝试删除通知对话的外键.
I am trying to remove the foreign key for notifications conversations.
我创建了一个迁移,上面写着:
I created a migration which says:
change_table :notifications do |t|
t.remove_foreign_key :conversations
但是,耙子中止并说不存在外键.
However, the rake aborts and says a foreign key does not exist.
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
我的架构包括: add_foreign_key通知",对话",名称:"notifications_on_conversation_id"
My schema includes: add_foreign_key "notifications", "conversations", name: "notifications_on_conversation_id"
我试图使db:migrate:down导致创建邮箱的原始迁移,但还出现一条错误消息,提示找不到命令".
I tried to rake db:migrate:down the original migration that created mailboxer, but also got an error saying 'command not found'.
任何人都可以帮忙吗?谢谢.
Can anyone help? Thank you.
推荐答案
模式中的add_foreign_key
命令为您的外键提供了名称notifications_on_conversation_id
.此名称不同于外国人通常根据列名称指定的默认名称,该名称为notifications_conversation_id_fk
.因此,您的remove_foreign_key
命令必须指定现有的外键名称而不是列名称.试试:
The add_foreign_key
command in your schema gave your foreign key the name notifications_on_conversation_id
. This name is different than the default name that foreigner would normally assign based on the column name, which is notifications_conversation_id_fk
. So your remove_foreign_key
command must specify the existing foreign key name instead of the column name. Try:
remove_foreign_key :notifications, name: "notifications_on_conversation_id"
这篇关于老外-删除外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!