AxD
AxD

Reputation: 3158

Can I have Entitiy Framework (Core) Migrations create database scripts?

In production my program is not allowed to emit DDL statements. I need to provide the database admins with a script that's performing these steps.

Can I have Entity Framework (Core) Migrations create some kind of a delta T-SQL script?

Upvotes: 2

Views: 350

Answers (2)

mattbloke
mattbloke

Reputation: 1146

I would expand on Steve Greene's answer in that if you want to script the delta changes you can do

dotnet ef migrations script <from migration> <to migration>

eg

dotnet ef migrations script AddNewTables AddAuditTable

to create a sql file you can do this

dotnet ef migrations script AddNewTables AddAuditTable -o update-script.sql

More detail here

https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/applying?tabs=dotnet-core-cli

Upvotes: 1

Steve Greene
Steve Greene

Reputation: 12304

Yes, there are a couple of ways:

1) Using Package Manager Console Tools for EF Core:

Script-Migration

2) Using the command line tools:

> dotnet ef migrations script -o scriptname.sql

Upvotes: 2

Related Questions