I am creating my database relationships using the code-first approach in .NET Entity Framework Core. Locally, if I run Add-Migration with Update-Database, the database is created with all of the correct tables.
For deployments, instead of running Update-Database, I'd like to use Script-Migration to generate SQL scripts. But the generated scripts assume a database already exists.
Here's what I've tried:
Add-Migration InitialMigration -Context MyContext
Script-Migration 0 InitialMigration -Context MyContext
But the generated scripts begin with table creation:
IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
BEGIN
CREATE TABLE [__EFMigrationsHistory] (
...
I read that I shouldn't combine Database.EnsureCreated() with migrations, so what is the best practice? Should I write the database creation portion myself?