开发者

Entity Framework 4.1: Code first error: "the model backing the context has changed since the database was created"

开发者 https://www.devze.com 2023-04-02 04:15 出处:网络
Im creating a database via a \"code first\" application, the sql server contains no databases. The application runs fine, creates the database and seeds the data i have defined in my initializer.
  1. Im creating a database via a "code first" application, the sql server contains no databases. The application runs fine, creates the database and seeds the data i have defined in my initializer.

  2. a service i have running tries to add some data to the database for the first time. i get the error:

The model backing the 'yyyContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

There should be no changes since the database was created and when then service runs.

I'm running EF4.1, and the database doesn't exist so unlike ques开发者_如何学运维tions with similar titles:

Database.SetInitializer<YourContext>(null);

Isn't the solution for me.

Any ideas about what could be wrong are welcome.


Doh! moment, turns out the service wasnt using the same connectionstring as the other app. the reason the databases didnt look the same must be because earlier in development i started the main app with no connectionstring aswell, so it provisioned a local instance database for itself to use.

Then later when i was trying to use the service, it was trying to access the same database from earlier, and the model changed significantly since then.

I pointed the connectionstring to the correct database and everything worked from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消