0

I am new to Entity-Framework-5 and IdentityDbContext, I have managed to create my and create the AspNet membership tables,then i changed the type in one of the properties of the model, now my project wont run and its telling me that I need to run migrations. My question is, how to run migrations on the IdentityDbContext? I cant find any good guides on how to do it.

Additional information: The model backing the 'ApplicationIdentityUserDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

public class ApplicationIdentityUserDbContext : IdentityDbContext<UserProfile> { public ApplicationIdentityUserDbContext() : base("DefaultConnection") { } } enter image description here I have attached the error when I run enable-migrations.

mahlatse
  • 1,322
  • 12
  • 24
  • running that show what dbContext I have, when I try to add a migration using configtypename, I get an error telling me that I cannot run migration on the specified dbConext – mahlatse Sep 25 '15 at 07:11
  • `oes not inherit from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. Migrations configuration types must extend from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'.` – mahlatse Sep 25 '15 at 07:37
  • You need to add migration for DBContext and not IdentityContext class. try this – VikrantMore Sep 25 '15 at 09:58
  • When I tried that, I got an error saying that the migartions is already enabled, and did not try the -force option as I was unsure of the changes it would have on my aspnet membership. – mahlatse Sep 25 '15 at 12:15

1 Answers1

-1

You do it by using the enable-migrations and add-migration command in the Package Manager Console See Code First Migrations

This will generate migration files which you can apply to the database using the update-database command (or they run automatically depending on settings).

Make sure to select the correct Default Project in the Package Manager Console, it should be the project containing your context.

Oberheim
  • 78
  • 11
  • 1
    I have two DBConext, one normal, and the other one I can run migration normaly, I cant add-migration an the IdentityContext class. – mahlatse Sep 25 '15 at 07:35
  • I ended up using the -force option to solve my problem, thanks, I marked the answer as correct as I used the same methodology to solve it. – mahlatse Sep 26 '15 at 02:42
  • I had similar issues with dotnet core 2.2 and it was due to misconfiguration in the Startup.cs class and the settings json file having a bad connection string. – Trevor Dec 27 '19 at 16:47