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 already an object named tblAbc in the database
Then I googled and everytime I get a stackoverflow link for suggesting to run Add-Migration Initial -IgnoreChanges
If I run this command and then run the update command, No error - Running seed method
But it doesn't sync the database with the new updates
Then I tried for number of times but same issue, hence I looked for some alternate solution & I got.
to use update-database -Script but if I run this command and get the following error.
User canceld Save dialog box
Then I tried to fix this by opening SQL Managment Studio and
Tools>>Options>>designers>> unchecked the Prevent saving changes that required table recreation
But after this also same error message.
Then I tried to add the following coniguration in my context class
System.Data.Entity.Database.SetInitializer(new MigrateDatabaseToLatestVersion <context, Configuration>());
It ran with success and Running Seed method but it doesn't sync the latest updates.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With