ASP.Net Identity Migrations

Vote:
 

Hi

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: 

Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.

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?

Regards

Farhad

#196025
Aug 16, 2018 14:26
Vote:
 

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.

#196050
Aug 17, 2018 9:08
Vote:
 

We had similar issues which was fixed by using an InitalizationModule

    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    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

#196052
Edited, Aug 17, 2018 9:57
Vote:
 

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

Regards

Farhad

#196060
Edited, Aug 17, 2018 11:47
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.