Entity Framework 5 Code First - How to Get Started?

I am using EF 5 Code First, successfully, in my application. I have about 40 tables. However, I ran into a problem that I can get Migrations to handle correctly. So, I would like to somehow tell EF to consider the current database schema as a new starting point and start managing it from that point. That way, I can make the necessary circuit changes manually and then say EF to start from now on.

Is there a way I can do this? I assume that I will have to delete the __MigrationHistory table or delete its contents. But I'm not sure how best to do this.

+6
source share
1 answer

You should be able to do the following:

  • Modify your database manually to reflect changes in the model that will not be processed during the migration. Now everything should work, but the database and the migration system are not synchronized.

  • Run Add-Migration ManuallyUpdatedDatabase -IgnoreChanges . This creates a migration that is completely empty, so it wonโ€™t make any changes to the database, but it will make sure that the system knows about manual changes. This way, manual changes will not be included in the next migration that you create.

  • Run Update-Database to apply empty migration.

From here, everything should work as usual. You simply have a โ€œmissing linkโ€ in your migrations because you manually processed some changes.

+8
source

Source: https://habr.com/ru/post/943634/


All Articles