DennisKRQ
DennisKRQ

Reputation: 185

EF Core Migration Potentially Destructive?

I'm setting up a .NET Core web service with EF Core integration and currently have migration configured for the DB schema (context.Migrate() is called in C# code). I'm wondering what would happen if EF Core detects an existing database for the given connection string that has vastly different schema such that it can't non-destructively migrate? Would EF Core nuke the existing DB and create the new schema or error out?

Upvotes: 0

Views: 345

Answers (1)

Kieran Devlin
Kieran Devlin

Reputation: 1433

EF Core would try and translate the migrations to SQL and the SQL would run. Because the schema's are different / not as expected, then the migrations would fail as an SQL Exception which would fall back up the chain to EF Core. (Essentially, the migration would fail and nothing would happen as everything is run under a transaction which is rolled back upon failure)

Upvotes: 1

Related Questions