有人知道在 Rails 3 中使用迁移创建外键的方法吗?
最佳答案
foreigner gem对我来说效果很好。它向 Rails 迁移添加了一些方法,可以轻松创建和删除外键:
示例:
create_table :site_credit_payments do |t|
t.decimal :amount, precision: 8, scale: 2, nil: false
t.string :note, nil: true
t.integer :credit_account_id
t.timestamps
end
add_foreign_key :site_credit_payments, :credit_accounts
关于ruby-on-rails - Rails 3 在迁移问题中添加外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3631717/