2

有谁知道使用迁移在 Rails 3 中创建外键的方法?

4

3 回答 3

3

外国人宝石对我很有效。它为 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
于 2013-08-28T17:48:17.287 回答
1

foreign_key_migrations,但我不喜欢那样。

于 2010-09-10T06:20:01.323 回答
0

如果您的应用程序具有 ActiveRecord::Migration(rails 3 应用程序可以),请使用add_foreign_key. 此处的文档:http: //araddconstraint.rubyforge.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html

请注意,这是一个插件,而不是 Active Record 的一部分。

于 2012-12-10T17:24:55.403 回答