I would like to know if it's possible to write a migration instead of of the following raw SQL statement:
execute <<-SQL
ALTER TABLE records
ADD CONSTRAINT fk_records_domains
FOREIGN KEY (domain_id)
REFERENCES domains(id) ON DELETE CASCADE
SQL
I would like avoid using sql because i'm getting problems when trying to rollback such migration:
execute <<-SQL
ALTER TABLE records
DROP FOREIGN KEY fk_records_categories
SQL
rake db:rollback
== Integrity: reverting ======================================================
-- execute(" ALTER TABLE records\n DROP FOREIGN KEY fk_records_categories\n")
rake aborted!
An error has occurred, all later migrations canceled:
Mysql2::Error: Error on rename of './BlackshardDev/records' to './BlackshardDev/#sql2-44cc-16c' (errno: 152): ALTER TABLE records
DROP FOREIGN KEY fk_records_categories
I know that activerecord can handle the referential integrity but i would like to be able to manage it also with the backend. Thanks