我想知道是否有可能寫遷移,而不是下面的原始SQL語句:Rails和參照完整性
execute <<-SQL
ALTER TABLE records
ADD CONSTRAINT fk_records_domains
FOREIGN KEY (domain_id)
REFERENCES domains(id) ON DELETE CASCADE
SQL
我將使用SQL,因爲我想要的時候得到的問題,如避免回滾這種遷移:
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
我知道activerecord可以處理參照完整性,但我希望能夠管理它也與後端。 感謝
感謝,老外好了:) – Dawid 2012-02-27 21:14:41