asp core ef migrations on production server
You can generate a migration script by running the following command:
Script-Migration -From older_migration_name -To newer_migration_name -Context ApplicationDbContext
The script will have a random name and will reside in the following path:
<Your_Project_Drive>:\<Your_Project_Folder>\<Your_Project_Folder.Model>\obj\Debug\netcoreapp3.1\<Some_Random_Name>.sql
Now just run that script on the targeted DB of production server.
There are a couple options:
- Generate a SQL script using
dotnet ef migrations script
and run it on your production database. - Call
dbContext.Database.Migrate()
at runtime during application startup (but be careful when running multiple apps/database clients)
Also, in the next release (1.0.0-preview3) of Microsoft.EntityFrameworkCore.Tools
, we'll be shipping ef.exe
which you can point directly to assemblies (instead of project.json
files) to perform migrations.