'Merging Entity Framework Database migration

I am working on an ASP.NET MVC, C#, Entity Framework, SQL Server project. We are using Code First approach. At present multiple developers are working on the project and I am not sure how to merge the database migration. The reason is, developers are making database changes using migrations and merging their changes without losing data seems challenging. For example,

Developer 1:

DB Change migration 1
DB Change migration 2
DB Change migration 5 
DB Change migration 6

Developer 2:
DB Change migration 1
DB Change migration 2
DB Change migration 3
DB Change migration 4

Developer 3:
DB Change migration 1
DB Change migration 2
DB Change migration 7

Expected final migration sequence after merging all developer changes,

DB Change migration 1
DB Change migration 2
DB Change migration 3
DB Change migration 4
DB Change migration 5
DB Change migration 6
DB Change migration 7

When we merge the code via VS 2019, the migration was not in the above sequence.

I tried to run the following command so that I can go back to a migration everyone has and reapply migrations one by one but, it did not work.

update-database -targetmigration DB Change migration 2 

I got an error that there are pending migrations.

Any suggestion / guidance on merging the database migration will be helpful.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source