Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails (`student_placement`.`programme_courses`, CONSTRAINT `fk_rails_5ab4b690d1` FOREIGN KEY (`programme_id`) REFERENCES `programmes` (`id`)) code example

Example: Cannot delete or update a parent row: a foreign key constraint fails (

ALTER TABLE "appointments" DROP FOREIGN KEY "appointments_user_id_foreign";

ALTER TABLE "appointments" ADD CONSTRAINT "appointments_user_id_foreign" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE;

Tags:

Sql Example