开发者

Rails 3 Add Foreign Key in Migration Problems

Does anyone know of a way to create a foreign key in Rails 3 using migrati开发者_如何学Goons?


the foreigner gem works well for me. it adds a few methods to Rails migrations that allow easy foreign key creation and deletion:

example:

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


foreign_key_migrations,but I dont like that.


If you're app has ActiveRecord::Migration (rails 3 apps do), use add_foreign_key. Documentation here: http://araddconstraint.rubyforge.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html

Note that this is a plugin and not a part of Active Record.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜