gpt4 book ai didi

ruby-on-rails - 当列与表不匹配时,如何可逆地删除表上的remove_foreign_key?

转载 作者:行者123 更新时间:2023-12-03 01:17:10 24 4
gpt4 key购买 nike

我尝试了以下方法

remove_foreign_key :users, :asset_types, column: :seek_asset_type_id

但出现错误

StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (given 3, expected 1..2)

文档说它使用与#add_foreign_key相同的选项。

Documentation

该列是之前创建的

add_reference :users, :seek_asset_type, foreign_key: {to_table: :asset_types}

这是定义:

"fk_rails_4dcaa1c59c" FOREIGN KEY (seek_asset_type_id) REFERENCES asset_types(id)

最佳答案

使用revert :

def change
revert do
add_reference :users, :seek_asset_type, foreign_key: { to_table: :asset_types }
end
end

另一种方法是通过名称恢复迁移:

def change
revert AddAssetTypeReferenceToUsers
# I made up this migration name,
# so please fill in the appropriate name
end

关于ruby-on-rails - 当列与表不匹配时,如何可逆地删除表上的remove_foreign_key?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46499493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com