Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sync Migrations and continue CodeFirst after manual DB edit

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!

like image 545
StefanDimi Avatar asked Oct 18 '25 05:10

StefanDimi


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.

like image 120
Pietro Avatar answered Oct 19 '25 22:10

Pietro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!