I found the following modification to add_foreign_key very useful:
def add_foreign_key(table, column, target_table, options = {})
o = {
:target_column => "id",
:constraint_name => "#{table.to_s}_#{target_table.to_s}_fkey",
:on_delete => nil
}.merge(options)
delete_action = "NO ACTION"
if o[:on_delete] == :restrict
delete_action = "RESTRICT"
elsif o[:on_delete] == :cascade
delete_action = "CASCADE"
else
raise "unexpected value for :on_delete! permitted: nil, :restrict, :cascade"
end
execute "ALTER TABLE #{table.to_s} ADD CONSTRAINT #{o[:constraint_name].to_s} FOREIGN KEY (#{column.to_s}) REFERENCES #{target_table.to_s} (#{o[:target_column].to_s}) ON DELETE #{delete_action};"
end
Yeah I had to do the same as well. MySQL 5.0.75