Rails gem / plugin for generating foreign key constraints.
sudo gem install phlawski-migration_fu --source http://gems.github.com
script/plugin install git://github.com/phlawski/migration_fu.git
----------------- ----------------- | users | | addresses | ----------------- ----------------- | id | | id | | username | <---- | user_id | | password | | street | ----------------- ----------------- [ON DELETE {RESTRICT | CASCADE | SET NULL | NO ACTION}] [ON UPDATE {RESTRICT | CASCADE | SET NULL | NO ACTION}] see http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html arguments: from_table, to_table, options => { :name, on_delete, on_update } add_foreign_key(:addresses, :users, :name => 'fk_add_user') add_foreign_key(:addresses, :users, :on_delete => :cascade) add_foreign_key(:addresses, :users, :on_delete => :set_null) add_foreign_key(:addresses, :users, :on_delete => :restrict) add_foreign_key(:addresses, :users, :on_delete => :no_action) add_foreign_key(:addresses, :users, :on_update => :cascade) add_foreign_key(:addresses, :users, :on_update => :set_null) add_foreign_key(:addresses, :users, :on_update => :restrict) add_foreign_key(:addresses, :users, :on_update => :no_action) add_foreign_key(:addresses, :users, :on_delete => :cascade, :on_update => :cascade) class CreateUsers < ActiveRecord::Migration def self.up create_table :users, :force => true do |t| t.string :username, :null => false t.string :password, :null => false end create_table :addresses, :force => true do |t| t.references :user t.string :street, :null => false end add_foreign_key(:addresses, :users, :on_delete => :cascade) end end