Skip to content Skip to sidebar Skip to footer

Update-database -force Command Is Not Updating The Base In Entity Framework Code -first

May be this question seems duplicate. But here are the issue that I am facing with the command. If I run this command, update-database -force the first error I gets.. There is a

Solution 1:

Using an Existing Database

Depending on the state of your context you need to the one of the following...

IF YOUR DATABASE CONTEXT CONTAINS ONLY YOUR EXISTING TABLES AND NO CUSTOM CHANGES DO THE FOLLOWING

Add-Migration Initial-IgnoreChanges

This will create a blank migration script

update-database

This will update the database to this migration but no changes will be applied. You can now add your changes to the database context. After you have finished do the following

Add-Migration Custom

This will generate a migration script with your changes in it. Then update your database again.

update-database

IF YOUR DATABASE CONTEXT CONTAINS YOUR EXISTING TABLES AND ALSO YOUR CUSTOM CHANGES

Add-migration Initial

This generates a migration script. Go through the migration script and remove any references to existing tables in both the UP and DOWN methods. You will be left with a script which only includes your custom logic.

update-database

Hope this helps!

Solution 2:

Update the migration file with the type, size and maxLength.

Example: maxLength: 50, type: "varchar(50)",

Properties:

Properties

Post a Comment for "Update-database -force Command Is Not Updating The Base In Entity Framework Code -first"