I am setting up a new Epi/Commerce instance. I ran the Epi scripts incuding update-epidatabase. I then decided decided to go with the ASP.Net Identity framework and I set everything up according to the EpiServer Tutorial. When logging into the CMS, and redirected to the migrate URL, I am currently running into the following error:
I ran the initial add-migration and also update-database but still getting the above error when trying to log into the EpiServer CMS. Any pointers?
This is not actually an Episerver issues but has something to do with Entity Framework and how you manage your migrations in there. The error you are seeing here is telling you that the model state that it currently has in the database does not match your model in code. You should be able to fix this by adding a new migration.
We had similar issues which was fixed by using an InitalizationModule
public class UserInitializationModule : IInitializableModule
public void Initialize(InitializationEngine context)
Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext<SjaAppUser>, Configuration>());
public void Uninitialize(InitializationEngine context)
//Add uninitialization logic
Replace thye SjaAppUser with whatever user model you are using
Thanks for the response. I managed to figure it out.
I created a custom Db context and I created the migrations, setup Asp.Net Identity etc. with that context. I called it EpiServerDbContext but when I am initializing the context in a initialization module, I am using the default context ApplicationDbContext. So, when the website runs, it initializes the ApplicationDbContext and not the custom one, hence the reason it is saying there are pending migrations, as the migrations initially were not run using the ApplicationDbContext but rather the custom one.
@Scott Reed I had the initialization module, but the issue was in that one line of code that initializes the Db i.e. I was using the wrong DbContext(ApplicationDbContext instead of my custom one). I have also marked your response as the correct one, as I think together with mine, it will help someone.
Appreciate the responses