Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Create Migration History table option on Ensure Created #10197

Closed
julielerman opened this Issue Oct 31, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@julielerman
Copy link

julielerman commented Oct 31, 2017

Describe what is not working as expected.
EnsureCreated doesn't create a migration history file
Migrate requires one or will attempt to run migrations whose schema has already been implemented in the database via EnsureCreated, causing the database to throw "already exists" errors.

Technically there is no reason to use EnsureCreated plus Migrate. Migrate does the same job.
However there's no compile time way to know about the confusing side effect.

Would it be possible to have an a parameter in EnsureCreated to just go ahead and build the migrationhistory file to protect against this problem?

Or is it possible for EF Core to wrap the database error inside of an EF Core error when the database throws "already exists" when Migrate is run?

Exception message:
Stack trace:

Steps to reproduce

Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

Console.WriteLine("Hello World!");

Further technical details

EF Core version: (found in project.csproj or packages.config)
Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Operating system:
IDE: (e.g. Visual Studio 2015)

@julielerman

This comment has been minimized.

Copy link
Author

julielerman commented Oct 31, 2017

I realize I wrote about this exact same thing 2 years ago, almost to the day, but got stumped by it yesterday for a few hours. http://thedatafarm.com/data-access/ef7-ensurecreated-vs-migrate-methods.

@ajcvickers

This comment has been minimized.

Copy link
Member

ajcvickers commented Nov 6, 2017

There are several complexities involved in trying to align Migrations and EnsureCreated. For example, if EnsureCreated doesn't use any existing migrations to create the database, then the database schema can be wrong, which causes a lot of confusion. On the other hand, having EF reliably find which migrations to use is difficult, so trying to use the existing migrations is also problematic. There are several other similar issues. Therefore, in EF Core we drew the line very clearly: use EnsureCreated or use Migrations.

Now, if you have been using EnsureCreated and want to stop doing that and start using Migrations, then this collapses into the same case as starting to use Migrations against an existing database, which is being tracked by #2167

@julielerman

This comment has been minimized.

Copy link
Author

julielerman commented Nov 6, 2017

fair enough. Thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.