Skip to content

Instantly share code, notes, and snippets.

@vadymberkut
Last active December 27, 2019 12:56
Show Gist options
  • Save vadymberkut/6ff9c38290b08fe0a51a5db21e3a4088 to your computer and use it in GitHub Desktop.
Save vadymberkut/6ff9c38290b08fe0a51a5db21e3a4088 to your computer and use it in GitHub Desktop.
Dotnet EF Migrations
dotnet ef migrations add {MigrationName}
dotnet ef migrations remove
dotnet ef database update
dotnet ef migrations add InitialIdentityServerMigration -c PersistedGrantDbContext
dotnet ef migrations add InitialIdentityServerMigration -c ConfigurationDbContext
dotnet ef migrations add InitialIdentityServerMigration -c ApplicationDbContext
dotnet ef migrations add Initial --context TelemetryDbContext --output-dir Migrations/TelemetryDb --project ../../Application.Persistence/Application.Persistence.Database
dotnet ef database update -c PersistedGrantDbContext
dotnet ef database update -c ConfigurationDbContext
dotnet ef database update -c ApplicationDbContext
# create db and apply migrations
dotnet ef database update --context TelemetryDbContext --project ./ --startup-project ../../Application.IotHubConsumer/IotHubConsumer.Telemetry
Add-Migration InitialIdentityServerMigration -Context PersistedGrantDbContext
Add-Migration InitialIdentityServerMigration -Context ConfigurationDbContext
Add-Migration InitialIdentityServerMigration -Context ApplicationDbContext
Add-Migration InitialIdentityServerMigration -Context PersistedGrantDbContext -o Migrations/PersistedGrantDb
Add-Migration InitialIdentityServerMigration -Context ConfigurationDbContext -o Migrations/ConfigurationDb
Add-Migration Identity -Context ApplicationDbContext -o Migrations/ApplicationDb
Remove-Migration -Context PersistedGrantDbContext
Remove-Migration -Context ConfigurationDbContext
Update-Database -Context PersistedGrantDbContext
Update-Database -Context ConfigurationDbContext
Update-Database -Context ApplicationDbContext
Add-Migration {Name}
Update-Database
Update-Database -Context ApplicationDbContext
Remove-Migration
Add-Migration AddUserAproved -Context ApplicationDbContext
Update-Database -Context ApplicationDbContext
---
Usage: dotnet ef migrations add [arguments] [options]
Arguments:
[name] The name of the migration
Options:
-o|--output-dir <path> The directory (and sub-namespace) to use. If omitted, "Migrations" is used. Relative paths are relative the directory in which the command is executed.
-c|--context <context> The DbContext to use. If omitted, the default DbContext is used
-e|--environment <environment> The environment to use. If omitted, "Development" is used.
--json Use json output. JSON is wrapped by '//BEGIN' and '//END'
-h|--help Show help information
-v|--verbose Enable verbose output
Alex Malik tips:
1 Restart VS 2017 after new dependancy added
2 Use following command to add migration:
Add-Migration -Name 'Test' -OutputDir './Database/Migrations' -Context OmChatDbContext -Project OmChat.Models -StartupProject OmChat.Web
3 Use following command to update database from the last migration:
Update-Database -Project OmChat.Models -StartupProject OmChat.Web -Context OmChatDbContext
4 Use following command to remove migration:
Remove-Migration -Project OmChat.Models -StartupProject OmChat.Web -Context OmChatDbContext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment