{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13154","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13154/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13154/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13154/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/13154","id":355314405,"node_id":"MDU6SXNzdWUzNTUzMTQ0MDU=","number":13154,"title":"HasData() creating deletes and re-inserts for unchanged entities on subsequent migrations","user":{"login":"collinbarrett","id":6483057,"node_id":"MDQ6VXNlcjY0ODMwNTc=","avatar_url":"https://avatars2.githubusercontent.com/u/6483057?v=4","gravatar_id":"","url":"https://api.github.com/users/collinbarrett","html_url":"https://github.com/collinbarrett","followers_url":"https://api.github.com/users/collinbarrett/followers","following_url":"https://api.github.com/users/collinbarrett/following{/other_user}","gists_url":"https://api.github.com/users/collinbarrett/gists{/gist_id}","starred_url":"https://api.github.com/users/collinbarrett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/collinbarrett/subscriptions","organizations_url":"https://api.github.com/users/collinbarrett/orgs","repos_url":"https://api.github.com/users/collinbarrett/repos","events_url":"https://api.github.com/users/collinbarrett/events{/privacy}","received_events_url":"https://api.github.com/users/collinbarrett/received_events","type":"User","site_admin":false},"labels":[{"id":76481852,"node_id":"MDU6TGFiZWw3NjQ4MTg1Mg==","url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/labels/type-bug","name":"type-bug","color":"f7c6c7","default":false}],"state":"open","locked":false,"assignee":{"login":"AndriySvyryd","id":6539701,"node_id":"MDQ6VXNlcjY1Mzk3MDE=","avatar_url":"https://avatars0.githubusercontent.com/u/6539701?v=4","gravatar_id":"","url":"https://api.github.com/users/AndriySvyryd","html_url":"https://github.com/AndriySvyryd","followers_url":"https://api.github.com/users/AndriySvyryd/followers","following_url":"https://api.github.com/users/AndriySvyryd/following{/other_user}","gists_url":"https://api.github.com/users/AndriySvyryd/gists{/gist_id}","starred_url":"https://api.github.com/users/AndriySvyryd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndriySvyryd/subscriptions","organizations_url":"https://api.github.com/users/AndriySvyryd/orgs","repos_url":"https://api.github.com/users/AndriySvyryd/repos","events_url":"https://api.github.com/users/AndriySvyryd/events{/privacy}","received_events_url":"https://api.github.com/users/AndriySvyryd/received_events","type":"User","site_admin":false},"assignees":[{"login":"AndriySvyryd","id":6539701,"node_id":"MDQ6VXNlcjY1Mzk3MDE=","avatar_url":"https://avatars0.githubusercontent.com/u/6539701?v=4","gravatar_id":"","url":"https://api.github.com/users/AndriySvyryd","html_url":"https://github.com/AndriySvyryd","followers_url":"https://api.github.com/users/AndriySvyryd/followers","following_url":"https://api.github.com/users/AndriySvyryd/following{/other_user}","gists_url":"https://api.github.com/users/AndriySvyryd/gists{/gist_id}","starred_url":"https://api.github.com/users/AndriySvyryd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndriySvyryd/subscriptions","organizations_url":"https://api.github.com/users/AndriySvyryd/orgs","repos_url":"https://api.github.com/users/AndriySvyryd/repos","events_url":"https://api.github.com/users/AndriySvyryd/events{/privacy}","received_events_url":"https://api.github.com/users/AndriySvyryd/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/milestones/46","html_url":"https://github.com/aspnet/EntityFrameworkCore/milestone/46","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/milestones/46/labels","id":3646712,"node_id":"MDk6TWlsZXN0b25lMzY0NjcxMg==","number":46,"title":"2.2.0","description":"","creator":{"login":"ajcvickers","id":1430078,"node_id":"MDQ6VXNlcjE0MzAwNzg=","avatar_url":"https://avatars1.githubusercontent.com/u/1430078?v=4","gravatar_id":"","url":"https://api.github.com/users/ajcvickers","html_url":"https://github.com/ajcvickers","followers_url":"https://api.github.com/users/ajcvickers/followers","following_url":"https://api.github.com/users/ajcvickers/following{/other_user}","gists_url":"https://api.github.com/users/ajcvickers/gists{/gist_id}","starred_url":"https://api.github.com/users/ajcvickers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajcvickers/subscriptions","organizations_url":"https://api.github.com/users/ajcvickers/orgs","repos_url":"https://api.github.com/users/ajcvickers/repos","events_url":"https://api.github.com/users/ajcvickers/events{/privacy}","received_events_url":"https://api.github.com/users/ajcvickers/received_events","type":"User","site_admin":false},"open_issues":122,"closed_issues":29,"state":"open","created_at":"2018-09-11T23:05:44Z","updated_at":"2018-09-24T22:16:19Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2018-08-29T20:10:40Z","updated_at":"2018-09-25T13:02:16Z","closed_at":null,"author_association":"NONE","body":"#### Issue\r\n\r\nWhen I add a migration after filling out some `HasData()` on a `modelBuilder.Entity<T>()`, the migration works well. However, if I add another migration immediately following (without changing anything), the second migration deletes and re-inserts all of the seed data again.\r\n\r\n#### Background\r\n\r\nI asked a [SO question](https://stackoverflow.com/questions/52067079/ef-core-2-1-seed-with-hasdata-from-external-source-such-as-json-file-without) yesterday, because I thought this was occurring because I was trying to seed from an external data source (.json files). However, I am seeing the same issue today with inline `new`-ing of seed data as the docs demonstrate.\r\n\r\nAny given piece of seed data, if left unmodified in `HasData()`, should only appear in `Up()` of a single migration, correct? This is my first go at using EF Core migrations with seed data, so it is certainly possible that I have something configured incorrectly, or I missed something in how the feature is supposed to work.\r\n\r\nThis could very well be a Pomelo (provider) issue as well. I am not versed enough in EF Core to know how to discern which it might be.\r\n\r\n### Steps to reproduce\r\n\r\n1. https://github.com/collinbarrett/FilterLists/commit/3786c835339e3663370b4225fc3fd05884d945cd Add the seed data. (I've seen suggested to use anonymous types to handle related data, but I did test with concrete types with the same result.)\r\n2. https://github.com/collinbarrett/FilterLists/commit/f241d3e928701682fa0356f356671eb81fe05644 Then I add the first migration, which looks/works great.\r\n3. Apply the migration by running the project which includes a call to `MyDbContext.Database.Migrate();`. Verified that seed data was successfully added to the db.\r\n4. https://github.com/collinbarrett/FilterLists/commit/e227e333d7be4607e1bb9b612c44b24a5952f670 Then, I immediately try adding another migration with no changes to the code, which (presumably erroneously) deletes and re-inserts all of the data.\r\n\r\n#### [Alternate 1: `uint` -> `int` for `Id`s](https://github.com/collinbarrett/FilterLists/commits/parse-metadata-int)\r\n\r\nSince I am somewhat swimming upstream using `uint`s as `Id` types (blocked by https://github.com/aspnet/EntityFrameworkCore/issues/11597 / https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/601), I tried temporarily converting all of these to `int`s, with the same results.\r\n\r\n1. https://github.com/collinbarrett/FilterLists/commit/4d7049d93b5a9aa3abdcff66eb89a3547b6887cf Convert types.\r\n2. https://github.com/collinbarrett/FilterLists/commit/f4720da3b394ea6e05d4a539c1a3ffbb6f843214 Initial migration.\r\n3. https://github.com/collinbarrett/FilterLists/commit/7f8bcfa9ded3ed89718e957ac47283efcc10ee1d Second migration (shows deletes and re-inserts).\r\n\r\n#### [Alternate 2: removing dynamic `DateTime`/`Timestamp`](https://github.com/collinbarrett/FilterLists/commits/parse-metadata-uint-datetime-fix)\r\n\r\nBecause I do have a couple `DateTime`s stored as `Timestamp`s in this entity, I tried a variant removing the `DateTime.Now` calculation of these values thinking that the dynamic nature of these properties caused a re-generation of the seed data in the migration. (ref: https://github.com/aspnet/EntityFrameworkCore/issues/11969)\r\n\r\n1. https://github.com/collinbarrett/FilterLists/commit/df5c1354f0440e0dde772369d9976f01876bc207 Remove `DateTime.Now()`.\r\n2. https://github.com/collinbarrett/FilterLists/commit/0f8fdd3474e8aae07abbdd9a31da617d65c6372d Initial migration.\r\n3. https://github.com/collinbarrett/FilterLists/commit/cbfda72ea1ae824a052fffe57619bc8f1b9b0c4a Second migration (shows deletes and re-inserts).\r\n\r\n#### [Alternate 3: Alternate 1 + Alternate 2](https://github.com/collinbarrett/FilterLists/commits/parse-metadata-int-datetime-fix) ([per](https://github.com/aspnet/EntityFrameworkCore/issues/13154#issuecomment-417092850))\r\n\r\n0. Branched from Alternate 1 (pre-migrations)\r\n1. https://github.com/collinbarrett/FilterLists/commit/fd33cbae49d73701b37d55a35899679bc0531a3b Remove `DateTime.Now()`.\r\n2. https://github.com/collinbarrett/FilterLists/commit/da5ae2bdf4cb17f2819a2646bad7c553c5ddafeb Initial migration.\r\n3. https://github.com/collinbarrett/FilterLists/commit/062988110eb58b207a04bd840f7d5cfdf9f1dd75 Second migration (shows deletes and re-inserts).\r\n\r\n### Further technical details\r\nEF Core version: 2.1.1\r\nDatabase Provider: Pomelo.EntityFrameworkCore.MySql (2.1.1)\r\nOperating system: Windows 10\r\nIDE: Visual Studio 2017 15.8.2\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/comments/424333787","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/13154#issuecomment-424333787","issue_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13154","id":424333787,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNDMzMzc4Nw==","user":{"login":"chrispickford","id":1290347,"node_id":"MDQ6VXNlcjEyOTAzNDc=","avatar_url":"https://avatars2.githubusercontent.com/u/1290347?v=4","gravatar_id":"","url":"https://api.github.com/users/chrispickford","html_url":"https://github.com/chrispickford","followers_url":"https://api.github.com/users/chrispickford/followers","following_url":"https://api.github.com/users/chrispickford/following{/other_user}","gists_url":"https://api.github.com/users/chrispickford/gists{/gist_id}","starred_url":"https://api.github.com/users/chrispickford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrispickford/subscriptions","organizations_url":"https://api.github.com/users/chrispickford/orgs","repos_url":"https://api.github.com/users/chrispickford/repos","events_url":"https://api.github.com/users/chrispickford/events{/privacy}","received_events_url":"https://api.github.com/users/chrispickford/received_events","type":"User","site_admin":false},"created_at":"2018-09-25T13:02:16Z","updated_at":"2018-09-25T13:02:16Z","author_association":"NONE","body":"Also experiencing this exact same issue, will endeavour to remove the duplicated `InsertData` and `DeleteData` statements from generated migrations until 2.2.0 drops."}}
{"actor":{"display_login":"chrispickford"}}