| Bug #68457 | EF Code First Migrations "cascadeDelete" sets ON DELETE RESTRICT | ||
|---|---|---|---|
| Submitted: | 21 Feb 2013 14:44 | Modified: | 11 Mar 2013 17:53 |
| Reporter: | Damien BRUN | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / NET | Severity: | S2 (Serious) |
| Version: | 6.6.5 | OS: | Windows |
| Assigned to: | Fernando Gonzalez.Sanchez | CPU Architecture: | Any |
[21 Feb 2013 14:44]
Damien BRUN
VS2012 project with simple migration
Attachment: CascadeDelete.zip (application/octet-stream, text), 1.15 MiB.
[11 Mar 2013 17:53]
John Russell
Added to changelog for 6.5.6: Setting cascadeDelete to true in DbMigration.AddForeignKey() results in ON DELETE RESTRICT foreign key constraints in generated DDL, rather than ON DELETE CASCADE as expected.

Description: setting cascadeDelete to true in DbMigration.AddForeignKey() results on "ON DELETE RESTRICT" foreign key constraints in generated DDL. How to repeat: Download Attached VS2012 project. Run "update-database" then launch app. It outputs "SHOW CREATE TABLE" on generated table : CREATE TABLE `children` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Parent_ID` int(11) NOT NULL, PRIMARY KEY (`ID`), KEY `IX_Parent_ID` (`Parent_ID`) USING HASH, CONSTRAINT `FK_Children_Parents_Parent_ID` FOREIGN KEY (`Parent_ID`) REFERENCE S `parents` (`ID`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=latin1 It should include : ON DELETE CASCADE Suggested fix: In \Source\MySql.Data.Entity\MySqlMigrationSqlGenerator.cs line 151, replace if (op.CascadeDelete) { sb.Append("on update cascade on delete restrict"); } with if (op.CascadeDelete) { sb.Append("on update cascade on delete cascade"); }