efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Issue with database-first to code-first transition.

Open WillBaldwin opened this issue 10 years ago • 3 comments

Steps to reproduce

  1. Install-Package Microsoft.EntityFrameworkCore.Tools -Pre
  2. Install-Package Microsoft.EntityFrameworkCore.SqlServer -Pre
  3. Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design -Pre
  4. cd src
  5. cd MyProject
  6. dotnet ef dbcontext scaffold -c ApplicationDbContext -o Models "Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer --force
  7. dotnet ef migrations add "Initial"
  8. dotnet ef database update

The issue

At this point (step 8), it would seem to me that since there were no changes to the model since the scaffold, there would be no updates. Dotnet-ef-database-update attempts to recreate the entire database schema. I think there used to be an -IgnoreChanges switch on add-migrations to help with this issue.

The goal

I want to start database first and have dotnet-ef-dbcontext-scaffold perform the heavy lifting of creating a ton of classes and setup the object relations based on the database schema. Then I want to switch to code-first; add Identity Framework to the project; and use dotnet-ef-migrations-add to add the identity tables using a migration then continue in a code-first fashion from then on. Perhaps my approach is wrong?

Further technical details

EF Core version:

    "Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final",

Operating system: Windows 10 Enterprise Visual Studio version: VS 2015 Enterprise

WillBaldwin avatar Jun 14 '16 21:06 WillBaldwin

Possibly a dupe of the scenario described in #2167

bricelam avatar Jun 15 '16 03:06 bricelam

Proposal #1 from #2167 "...add a way to point our reverse engineering engine to the existing database to obtain a model snapshot (and possibly an accompanying initial migration)." would seem to address the issue.

WillBaldwin avatar Jun 15 '16 13:06 WillBaldwin

Closing as dupe

rowanmiller avatar Jun 15 '16 18:06 rowanmiller