Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Code Frirst: Before you update your database using Code First Migrations,

I just updated EntityFramework from V6.0.2 to V6.1 and also to the latest ASP.NET Identity. After that I tried to create a migration file for limiting the length of the username which is now possible with the new version of ASP.NET Identity Framework released today.

This is the error message I got:

The model backing the 'ApplicationDbContext' context has changed since the database was created. This could have happened because the model used by ASP.NET Identity Framework has changed or the model being used in your application has changed. To resolve this issue, you need to update your database. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=301867). Before you update your database using Code First Migrations, please disable the schema consistency check for ASP.NET Identity by setting throwIfV1Schema = false in the constructor of your ApplicationDbContext in your application. public ApplicationDbContext() : base("ApplicationServices", throwIfV1Schema:false)

I'm especially interested in this line:

Before you update your database using Code First Migrations, please disable the schema consistency check for ASP.NET Identity by setting throwIfV1Schema = false in the constructor of your ApplicationDbContext in your application.

Why would I want to do that? And for how 'long'?

Also, I haven't changed anything in the model since before and after the update.

like image 271
Yustme Avatar asked Mar 20 '14 23:03

Yustme


People also ask

How do I code my first migration to an existing database?

Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.

How do I update my database in migration?

After creating a migration file using the add-migration command, you have to update the database. Execute the Update-Database command to create or modify a database schema. Use the –verbose option to view the SQL statements being applied to the target database.


1 Answers

Bool param throwIfV1Schema throws exception that asp.net Identity model has been changed (updated to new version 2).

Change your IdentityDbContext constructor for one time migration:

public YourDbContext() : base("YourConnectionString", throwIfV1Schema:false){}
like image 137
Arvis Avatar answered Dec 30 '22 18:12

Arvis