Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework 4.3.1 add-migration error: "model backing the context has changed"
    primarykey
    data
    text
    <p>I'm getting an error when trying to run the EF 4.3.1 add-migrations command:</p> <p>"The model backing the ... context has changed since the database was created". </p> <p>Here's one sequence that gets the error (although I've tried probably a dozen variants which also all fail)...</p> <p>1) Start with a database that was created by EF Code First (ie, already contains a _MigrationHistory table with only the InitialCreate row).</p> <p>2) The app's code data model and database are in-sync at this point (the database was created by CF when the app was started).</p> <p>3) Because I have four DBContexts in my "Services" project, I didn't run 'enable-migrations' command (it doesn't handle multipe contexts). Instead, I manually created the Migrations folder in the Services project and the Configuration.cs file (included at end of this post). [I think I read this in a post somewhere] </p> <p>4) With the database not yet changed, and the app stopped, I use the VS EDM editor to make a trivial change to my data model (add one property to an existing entity), and have it generate the new classes (but not modify the database, obviously). I then rebuild the solution and all looks OK (but don't delete the database or restart the app, of course).</p> <p>5) I run the following PMC command (where "App" is the name of one of the classes in Configuration.cs):</p> <p>PM> add-migration App_AddTrivial -conf App -project Services -startup Services -verbose</p> <p>... which fails with the "The model ... has changed. Consider using Code First Migrations..." error.</p> <p>What am I doing wrong? And does anyone else see the irony in the tool telling me to use what I'm already trying to use ;-)</p> <p>What are the correct steps for setting-up a solution starting with a database that was created by EF CF? I've seen posts saying to run an initial migration with -ignorechanges, but I've tried that and it doesn't help. Actually, I've spent all DAY testing various permutations, and nothing works!</p> <p>I must be doing something really stupid, but I don't know what!</p> <p>Thanks,</p> <p>DadCat</p> <p>Configuration.cs:</p> <p>namespace mynamespace { internal sealed class App : DbMigrationsConfiguration { public App() { AutomaticMigrationsEnabled = false; MigrationsNamespace = "Services.App.Repository.Migrations"; }</p> <pre><code> protected override void Seed(.Services.App.Repository.ModelContainer context) { } } internal sealed class Catalog : DbMigrationsConfiguration&lt;Services.Catalog.Repository.ModelContainer&gt; { public Catalog() { AutomaticMigrationsEnabled = false; MigrationsNamespace = "Services.Catalog.Repository.Migrations"; } protected override void Seed(Services.Catalog.Repository.ModelContainer context) { } } internal sealed class Portfolio : DbMigrationsConfiguration&lt;Services.PortfolioManagement.Repository.ModelContainer&gt; { public Portfolio() { AutomaticMigrationsEnabled = false; MigrationsNamespace = "Services.PortfolioManagement.Repository.Migrations"; } protected override void Seed(Services.PortfolioManagement.Repository.ModelContainer context) { } } internal sealed class Scheduler : DbMigrationsConfiguration&lt;.Services.Scheduler.Repository.ModelContainer&gt; { public Scheduler() { AutomaticMigrationsEnabled = false; MigrationsNamespace = "Services.Scheduler.Repository.Migrations"; } protected override void Seed(Services.Scheduler.Repository.ModelContainer context) { } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload