0

We have a SQL database that we are managing via entity framework migrations and we have 3 DbContexts, each with their own migrations. This works well most of the time, however, we have an issue from time to time where the context key for 2 of the migrations, gets overridden with a context key from another migration. i.e.enter image description here

However, it should look like:

enter image description here

Does anyone have any idea how this is even happening? It is starting to become very frustrating.

Daniel Mackay
  • 2,298
  • 1
  • 15
  • 19
  • Are the migrations separated into different folders or projects? You might try explicitly setting the ContextKey in the Configuration() constructor. Another option is to [create multiple __MigrationHistory in different schemas](http://stackoverflow.com/questions/11197754/entity-framework-one-database-multiple-dbcontexts-is-this-a-bad-idea). – Steve Greene Jan 30 '17 at 15:45
  • The migrations are all in separate projects. The context key is explicitly set for PSContext and NotificationContext. ApplicationDbContext looks like it's being set, but this is handled by ASP.NET Identity. The strange thing is that when the DB is intially created, all migrations have the correct ContextKey, but at some stage they all get overidden by NotificationContext. Once this happens PSContext will try to create tables as it think's it's migrations have not run. However, the tables already exists and the migration fails. – Daniel Mackay Jan 30 '17 at 21:09

0 Answers0