Sync Migrations and continue CodeFirst after manual DB edit

Viewed 48

I was using code-first migrations in a .NET Core project with a SQL Server database. But due to unblocking himself, my coworker had to manually change the database tables. Is there an elegant way to sync up migrations with the database, and continue using code-first after manual interference?

Just a bit more insights, this is the error:

Column names in each table must be unique. Column name 'xxx' in table 'xxx' is specified more than once.

Of course - this is due to the column that already exists in the database.

Thanks!

1 Answers

It is possible when your changes are matching his.

Just use Script-Migration command and from the generated script remove the commands(alter, create, etc) which are already in place in the target database.

At the end keep the INSERT INTO [__EFMigrationsHistory] ... command.

Related