我想从自定义礼服表中删除User
belongs_to
关系。
这是我定制的着装迁移:
class CreateCustomisedDresses < ActiveRecord::Migration
def change
create_table :customised_dresses do |t|
t.belongs_to :user, index: true, null: :false
t.timestamps null: false
end
add_foreign_key :customised_dresses, :users, dependent: :delete
end
我尝试了以下迁移,但它给了我一个错误:
class RemoveForeignKeyUsersFromCustomisedDresses < ActiveRecord::Migration
def self.up
add_foreign_key :customised_dresses, :users
end
def self.down
remove_foreign_key :customised_dresses, :users
end
end
答案 0 :(得分:1)
您应该使用上下方法交换代码:
class RemoveForeignKeyUsersFromCustomisedDresses < ActiveRecord::Migration
def self.up
remove_foreign_key :customised_dresses, :users
end
def self.down
add_foreign_key :customised_dresses, :users
end
end