EF Core Migrations manual edits possible?

ef-core-2.0 ef-migrations entity-framework entity-framework-core

Question

I am using EF Core 2.0 in my sample project with some value object configurations. I modify the code and generate migrations via CLI command line. In the last migration rather than adding a new database table as it should, it is trying to rename existing tables to each other and create an extra table for existing one. I could not figure out the reason for it.

Issue is, since with EF Core the snapshot is a separate auto-generated file from the migration itself I don't want to modify the snapshot.

I only want to modify the migration script so that it will not rename multiple tables, and then generate the snapshot from the migrations I created.

I did not see any command for this in the CLI - is it such a bad practice to modify the scaffolded migration and regenerate or am I missing some obvious new link where how to manually modify migration scripts is explained?

Thanks a bunch.

Update 1: After comments, added info about the snapshot from this link.

Because the current database schema is represented in code, EF Core doesn't have to interact with the database to create migrations. When you add a migration, EF determines what changed by comparing the data model to the snapshot file. EF interacts with the database only when it has to update the database. +

1
2
11/24/2017 11:43:11 AM

Accepted Answer

I examined my generated snapshot code from source control. It exactly has added one extra table as what I needed.

The migration script to generate this is hectic at best - renaming multiple tables to each other and then warning that this could break causing multiple issues.

Since this is a sample project for me with only mock data as of now at least, I decided to go for it and not break the automated scripts. I am willing to lose some mock data at this stage rather than wasting time on it.

If this were in a production database I would be extremely careful to manually create the same result with intervention modifying both the scaffold and the migration file.

I am accepting this one as an answer (basically saying current EF Core does not support it to the best of my current knowledge) since there is no other candidate now - I will be more than glad to accept if any better answer shows up.

1
11/24/2017 6:43:41 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow