Does anyone know of a way to create a foreign key in Rails 3 using migrations?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
- Rails how to handle error and exceptions in model
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Rspec controller error expecting <“index”> but
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.htmlNote that this is a plugin and not a part of Active Record.
the foreigner gem works well for me. it adds a few methods to Rails migrations that allow easy foreign key creation and deletion:
example: