Entity Framework Core: Generate SQL Script
This command helps you generate SQL scripts that you can use to deploy migrations to a production environment. To deploy migrations to a local database, you can also use the Update Database command.
Under the hood, JetBrains Rider will apply the dotnet ef migrations script
command with the corresponding arguments. Make sure that dotnet ef
global tool is installed on your machine.
Do one of the following:
Right-click the desired project in the Solution Explorer and choose
.Select
from the main menu.
A dialog will appear where you can specify all necessary options.
In the dialog, specify options for generating the SQL script. By default, JetBrains Rider saves the options from previous invocations of EF Core commands and automatically fills most of the fields . If you want to disable this, clear the Autofill general options checkbox on the Tools | EF Core UI settings page Ctrl+Alt+S.
Click OK to apply the command. JetBrains Rider will execute the
ef core migrations script
command with the corresponding arguments.By default, the command output will be displayed in a new tab of the EF Core tool window. If you prefer to see the command progress in the status bar and the results of the command in a popup, clear the Execute commands in terminal checkbox on the Tools | EF Core UI settings page Ctrl+Alt+S.
Below is the list of options for the Generate SQL Script command.
Common | |
From migration To migration | Select the range of migrations that will be used in the generated script. To generate a rollback script, you can specify a newer migration in From migration and an older migration in To migration. |
Migrations project | The project where the command will be applied. If you have invoked the command from the context menu of a specific project, this project will be preselected. |
Startup project | Project to be run when you start your application, containing the entry point or startup logic (like the |
DbContext class |
|
Additional Options | |
Output file | The name of the SQL file where the script is saved. The file will be added to the solution root directory. |
Make script idempotent | Idempotent scripts verify which migrations have been executed using the migration history table and apply only missing migrations. You can select this option if the last migration applied to the database is unknown or when using the script for several databases that might be at different migration stages. |
No transactions | Do not generate SQL transaction statements. |
Build Options | |
Skip project build process | Use this option when the build is up to date. Although this option reduces the execution time of the command, it may also be a source of potential problems if the project has not been built before running the command. |
Build configuration | Build configuration of the startup project, for example, |
Target framework | Target runtime to restore packages for when building the startup project. |
Execution | |
Enable diagnostic logging | Show verbose output if the Execute commands in terminal checkbox is enabled on the Tools | EF Core UI settings page Ctrl+Alt+S. |
Additional arguments | Any additional arguments to pass to the application. |