Modika
Modika

Reputation: 6282

Resetting Context for Entity Framework 5 so it thinks its working with a initialised Database - Code First

Linked to this question:

Cannot Split Table with EF 5 - Code First - with existing database

But i think the answer to that question is actually not a problem with code first but with something i did whilst developing.

The scenario is this:

  1. Had an existing database and used this to begin creating my data context
  2. Began working with it but soon realised that naming conventions were poor and some tables needed remodelling.
  3. Decided to create a new database with better conventions for existing tables taken across and remodelled the new bits
  4. Updated the context to look at new Database
  5. Even though migrations where not enabled, i was getting errors with the database being out of sync (even though up until this morning it was still pulling data)
  6. I enabled migrations (comment in other question) and output to script. And you can see the sync changes are things like table names and Id properties etc.

I can't move forwards, the context seems does not like it when you switch databases on it like this (which i get to a point but this is really brittle). What i need to do somehow reset the context so it doesn't actually think any changes have been made to the database and it thinks it is working with an initial database again.

I have deleted the migrations folder, but that does nothing. Is there a any sort of way i can get this to happen?

Upvotes: 0

Views: 438

Answers (1)

Jamie Burns
Jamie Burns

Reputation: 1318

Try deleting the __MigrationHistory table in the database. It's a system one.

Upvotes: 2

Related Questions