0

New to data migrations and entity framework. I have inherited a project which uses this. I have a field in a table which is used as a flag and is updated using a trigger on the table. I would like to access this field in my web project. I have added the property to the model but when I build and run the project I get 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 think I need to go Package Manager Console and run Add-Migration 'MigrationName'

I don't know the correct way to do this so that:

  1. The existing data is retained

Can any one point me in the right direction of how to do this or the correct terminology to do a google search for an answer?

Ros
  • 634
  • 3
  • 18
  • 34
  • Have you tried to run *update-database* command in package manager console? – Alexander Jan 31 '19 at 17:26
  • Possible duplicate https://stackoverflow.com/questions/20968520/entity-framework-code-first-migration-fails-with-update-database-forces-unnecc – Alexander Jan 31 '19 at 17:38

1 Answers1

0

Running Add-Migration is a safe thing to do, that won't do any changes in your database, it will generate a migration file, and then if you want you can edit it or add some additional changes and scripts to it, and if you like it you can run the Update-Database command which will apply these changes to your database.

And even if you applied the changes on your DB, and you realized that it has some issues, you can still roll back to a specific migration with the Update-Database -TargetMigration:"name_of_migration" command.

hujtomi
  • 1,540
  • 2
  • 17
  • 23