7

I'm create a web app using Asp.net core with EntityFramework core, but the Update-Database command no longer has the "-Script" switch. How can I get the sql script? Thanks.

2 Answers 2

8

Run this command to produce the SQL Script

> dotnet ef migrations script -o fileName.sql

Also there's a powershell command for it too: powershell#script-migration

Sign up to request clarification or add additional context in comments.

3 Comments

For me it does not work. I am getting a file with just the IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL BEGIN CREATE TABLE [__EFMigrationsHistory] ( [MigrationId] nvarchar(150) NOT NULL, [ProductVersion] nvarchar(32) NOT NULL, CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) ); END; GO. While I also have a few entities setup. Maybe you know I may be missing?
It has from and to parameters too. Try to specify them explicitly.
The problem was that first before executing the command I had to generate migrations.
1

I come at this question to find command that can generate script for all tables/db objects from dbcontext. If you are also looking same instead of just migration or update, command is :

dotnet ef dbcontext script -o filename.sql 

Just open the command prompt in folder in which entity framework exist & run this. this will create SQL file in same folder.

Just make sure you have dotnet ef tools installed, if not already use

dotnet tool install --global dotnet-ef

before the above context command.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.