1ADD_FOREIGN_KEYS = """ 2ALTER TABLE tests MODIFY COLUMN job_idx int(10) unsigned NOT NULL; 3 4DELETE FROM tests WHERE job_idx NOT IN (SELECT job_idx FROM jobs); 5 6ALTER TABLE tests ADD CONSTRAINT tests_to_jobs_ibfk 7 FOREIGN KEY (job_idx) REFERENCES jobs (job_idx); 8""" 9 10DROP_FOREIGN_KEYS = """ 11ALTER TABLE tests DROP FOREIGN KEY tests_to_jobs_ibfk; 12ALTER TABLE tests MODIFY COLUMN job_idx int(11) NOT NULL; 13""" 14 15def migrate_up(mgr): 16 mgr.execute_script(ADD_FOREIGN_KEYS) 17 18def migrate_down(mgr): 19 mgr.execute_script(DROP_FOREIGN_KEYS) 20