{"action":"created","issue":{"url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/147","repository_url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql","labels_url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/147/labels{/name}","comments_url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/147/comments","events_url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/147/events","html_url":"https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/147","id":194280182,"number":147,"title":"Cascade delete on one-to-one relationships not working","user":{"login":"joacar","id":439028,"avatar_url":"https://avatars.githubusercontent.com/u/439028?v=3","gravatar_id":"","url":"https://api.github.com/users/joacar","html_url":"https://github.com/joacar","followers_url":"https://api.github.com/users/joacar/followers","following_url":"https://api.github.com/users/joacar/following{/other_user}","gists_url":"https://api.github.com/users/joacar/gists{/gist_id}","starred_url":"https://api.github.com/users/joacar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joacar/subscriptions","organizations_url":"https://api.github.com/users/joacar/orgs","repos_url":"https://api.github.com/users/joacar/repos","events_url":"https://api.github.com/users/joacar/events{/privacy}","received_events_url":"https://api.github.com/users/joacar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-08T08:59:55Z","updated_at":"2016-12-09T18:56:20Z","closed_at":null,"body":"Hi,\r\n\r\nFirst of, great work!\r\n\r\n### Steps to reproduce\r\nI have a model roughly\r\n\r\n````c#\r\npublic class Profile\r\n{\r\n// Other properties excluded for brevity\r\npublic InstagramChannel Instagram { get; set;}\r\n\r\npublic BlogChannel Blog { get; set;}\r\n}\r\n\r\npublic class BlogChannel\r\n{\r\n}\r\n\r\npublic class InstagramChannel\r\n{\r\n\r\n}\r\n````\r\n\r\nIn the model builder I configure them like so\r\n\r\n````c#\r\nmodelBuilder.Entity<Profile>()\r\n    .HasOne(profile => profile.Instagram)\r\n    .WithOne(typeof(InstagramChannel), \"ProfileId\")\r\n    .HasForeignKeyConstraint(\"FK_Profile_Id\")\r\n    .OnDelete(DeleteBehavior.Delete);\r\n````\r\n\r\n\r\nIt works for a many-to-many relationship that I've set up for `Profile, Category and ProfileCategory join table`. That is - deleting a profile successfully removes the entries in `ProfileCategory`\r\n\r\n### The issue\r\n// Fetch profile\r\nvar profile = await _context.Profiles.Include(p => p.Instagram).FirstOrDefaultAsync(p => p.Id == id);\r\n_context.Profiles.Remove(profile);\r\nawait _context.SaveChangesAsync();\r\n// Succeeds but the InstagramChannel entity is still int the database with `ProfileId = NULL`\r\n\r\nIf you are seeing an exception, include the full exceptions details (message and stack trace).\r\n\r\n```\r\nException message:\r\nStack trace:\r\n```\r\n\r\n### Further technical details\r\n\r\nMySQL version: 5.6.10\r\nOperating system: macOS Sierra 10.12.1\r\nPomelo.EntityFrameworkCore.MySql version: 1.1.0\r\n\r\nOther details about my project setup:\r\nThis is the generated code from the `.cs` file\r\n````c#\r\n\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing Microsoft.EntityFrameworkCore.Migrations;\r\n\r\nnamespace App.Migrations\r\n{\r\n    public partial class _1 : Migration\r\n    {\r\n        protected override void Up(MigrationBuilder migrationBuilder)\r\n        {\r\n            migrationBuilder.CreateTable(\r\n                name: \"Profiles\",\r\n                columns: table => new\r\n                {\r\n                    Id = table.Column<int>(nullable: false)\r\n                        .Annotation(\"MySql:ValueGeneratedOnAdd\", true),\r\n                    BlogId = table.Column<int>(nullable: true),\r\n                    City = table.Column<string>(nullable: false),\r\n                    CivilStatus = table.Column<int>(nullable: false),\r\n                    Country = table.Column<string>(nullable: true),\r\n                    DateOfBirth = table.Column<string>(maxLength: 10, nullable: true),\r\n                    Description = table.Column<string>(nullable: true),\r\n                    Email = table.Column<string>(nullable: true),\r\n                    FullName = table.Column<string>(nullable: false),\r\n                    Gender = table.Column<int>(nullable: false),\r\n                    ImageUrl = table.Column<string>(nullable: true),\r\n                    InstagramId = table.Column<string>(nullable: true),\r\n                    Mobile = table.Column<string>(nullable: true),\r\n                    Url = table.Column<string>(nullable: true)\r\n                },\r\n                constraints: table =>\r\n                {\r\n                    table.PrimaryKey(\"PK_Profiles\", x => x.Id);\r\n                });\r\n\r\n            migrationBuilder.CreateTable(\r\n                name: \"BlogChannel\",\r\n                columns: table => new\r\n                {\r\n                    Id = table.Column<int>(nullable: false)\r\n                        .Annotation(\"MySql:ValueGeneratedOnAdd\", true),\r\n                    Author = table.Column<string>(nullable: true),\r\n                    CreatedAtUtc = table.Column<DateTime>(nullable: false, defaultValueSql: \"current_timestamp(6)\")\r\n                        .Annotation(\"MySql:ValueGeneratedOnAdd\", true),\r\n                    Description = table.Column<string>(nullable: true),\r\n                    ImageUrl = table.Column<string>(nullable: true),\r\n                    PageViewsLastMonth = table.Column<int>(nullable: false),\r\n                    PageViewsLastWeek = table.Column<int>(nullable: false),\r\n                    ProfileId = table.Column<int>(nullable: true),\r\n                    UpdatedAtUtc = table.Column<DateTime>(nullable: false, defaultValueSql: \"current_timestamp(6)\")\r\n                        .Annotation(\"MySql:ValueGeneratedOnAddOrUpdate\", true),\r\n                    Url = table.Column<string>(nullable: true)\r\n                },\r\n                constraints: table =>\r\n                {\r\n                    table.PrimaryKey(\"PK_BlogChannel\", x => x.Id);\r\n                    table.ForeignKey(\r\n                        name: \"FK_Blog_Profile\",\r\n                        column: x => x.ProfileId,\r\n                        principalTable: \"Profiles\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Cascade);\r\n                });\r\n\r\n            migrationBuilder.CreateTable(\r\n                name: \"InstagramChannel\",\r\n                columns: table => new\r\n                {\r\n                    Id = table.Column<string>(nullable: false)\r\n                        .Annotation(\"MySql:ValueGeneratedOnAdd\", true),\r\n                    Bio = table.Column<string>(nullable: true),\r\n                    CreatedAtUtc = table.Column<DateTime>(nullable: false, defaultValueSql: \"current_timestamp(6)\")\r\n                        .Annotation(\"MySql:ValueGeneratedOnAdd\", true),\r\n                    FollowedBy = table.Column<int>(nullable: false),\r\n                    FullName = table.Column<string>(nullable: true),\r\n                    ImageUrl = table.Column<string>(nullable: true),\r\n                    ProfileId = table.Column<int>(nullable: true),\r\n                    UpdatedAtUtc = table.Column<DateTime>(nullable: false, defaultValueSql: \"current_timestamp(6)\")\r\n                        .Annotation(\"MySql:ValueGeneratedOnAddOrUpdate\", true),\r\n                    Username = table.Column<string>(nullable: true),\r\n                    Website = table.Column<string>(nullable: true)\r\n                },\r\n                constraints: table =>\r\n                {\r\n                    table.PrimaryKey(\"PK_InstagramChannel\", x => x.Id);\r\n                    table.ForeignKey(\r\n                        name: \"FK_Instagram_Profile\",\r\n                        column: x => x.ProfileId,\r\n                        principalTable: \"Profiles\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Cascade);\r\n                });\r\n\r\n           \r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_BlogChannel_ProfileId\",\r\n                table: \"BlogChannel\",\r\n                column: \"ProfileId\",\r\n                unique: true);\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_InstagramChannel_ProfileId\",\r\n                table: \"InstagramChannel\",\r\n                column: \"ProfileId\",\r\n                unique: true);\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_Profiles_BlogId\",\r\n                table: \"Profiles\",\r\n                column: \"BlogId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_Profiles_InstagramId\",\r\n                table: \"Profiles\",\r\n                column: \"InstagramId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_ProfileCategories_ProfileId\",\r\n                table: \"ProfileCategories\",\r\n                column: \"ProfileId\");\r\n\r\n            migrationBuilder.AddForeignKey(\r\n                name: \"FK_Profiles_BlogChannel_BlogId\",\r\n                table: \"Profiles\",\r\n                column: \"BlogId\",\r\n                principalTable: \"BlogChannel\",\r\n                principalColumn: \"Id\",\r\n                onDelete: ReferentialAction.Restrict);\r\n\r\n            migrationBuilder.AddForeignKey(\r\n                name: \"FK_Profiles_InstagramChannel_InstagramId\",\r\n                table: \"Profiles\",\r\n                column: \"InstagramId\",\r\n                principalTable: \"InstagramChannel\",\r\n                principalColumn: \"Id\",\r\n                onDelete: ReferentialAction.Restrict);\r\n        }\r\n\r\n        protected override void Down(MigrationBuilder migrationBuilder)\r\n        {\r\n            migrationBuilder.DropForeignKey(\r\n                name: \"FK_Blog_Profile\",\r\n                table: \"BlogChannel\");\r\n\r\n            migrationBuilder.DropForeignKey(\r\n                name: \"FK_Instagram_Profile\",\r\n                table: \"InstagramChannel\");\r\n\r\n            migrationBuilder.DropTable(\r\n                name: \"ProfileCategories\");\r\n\r\n            migrationBuilder.DropTable(\r\n                name: \"Categories\");\r\n\r\n            migrationBuilder.DropTable(\r\n                name: \"Profiles\");\r\n\r\n            migrationBuilder.DropTable(\r\n                name: \"BlogChannel\");\r\n\r\n            migrationBuilder.DropTable(\r\n                name: \"InstagramChannel\");\r\n        }\r\n    }\r\n}\r\n````\r\n"},"comment":{"url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/comments/266092395","html_url":"https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/147#issuecomment-266092395","issue_url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/147","id":266092395,"user":{"login":"mguinness","id":14002844,"avatar_url":"https://avatars.githubusercontent.com/u/14002844?v=3","gravatar_id":"","url":"https://api.github.com/users/mguinness","html_url":"https://github.com/mguinness","followers_url":"https://api.github.com/users/mguinness/followers","following_url":"https://api.github.com/users/mguinness/following{/other_user}","gists_url":"https://api.github.com/users/mguinness/gists{/gist_id}","starred_url":"https://api.github.com/users/mguinness/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mguinness/subscriptions","organizations_url":"https://api.github.com/users/mguinness/orgs","repos_url":"https://api.github.com/users/mguinness/repos","events_url":"https://api.github.com/users/mguinness/events{/privacy}","received_events_url":"https://api.github.com/users/mguinness/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T18:56:20Z","updated_at":"2016-12-09T18:56:20Z","body":"Referential actions are shown as as NO ACTION instead of CASCADE in MySQL.\r\n\r\nhttps://docs.microsoft.com/en-us/ef/core/api/microsoft.entityframeworkcore.metadata.deletebehavior\r\n\r\nWhat does your migration script show?  You had `onDelete: ReferentialAction.Restrict` initially and you now have `OnDelete(DeleteBehavior.Cascade)`?  Have you applied all migrations?"}}
{"actor":{"display_login":"mguinness"}}