Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Allow Create Migration History table option on Ensure Created #10197
Describe what is not working as expected.
Technically there is no reason to use EnsureCreated plus Migrate. Migrate does the same job.
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?
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.
Further technical details
EF Core version: (found in project.csproj or packages.config)
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.
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