3

How do I get EF to build all the tables for the prod db?

So far I've been building and pushing all my .Net Core database migrations to the dev db

ex.

>dotnet ef migrations add InitialModsN -c Auto2Context

>dotnet ef database update -c Auto2Context

In my Appsettings.Development.json file I have my con string pointing to dev db 'source=DEV'

"ConnectionStrings": {
"DefaultConnection": "Data Source=Auto2.db",
"Auto2": "data source=DEV; initial catalog=Auto2; user id=auto2; password=12345;" }

And my Appsettings.json I have the prod db con string pointing to the prod db 'source=LIVE'

"ConnectionStrings": {
"DefaultConnection": "Data Source=Auto2.db",
"Auto2": "data source=LIVE; initial catalog=Auto2; user id=auto2; password=12345;" }

So far everything is being built and migrated to dev, how do I change this to build all the changes up to date in the prod db?

Do I have to re create an initial migration file and then update? If yes, how do I point it to the prod db? I tried a couple of different commands with no luck. Here is what I tried.

>dotnet ef database update -c Auto2Context --connection "data source=LIVE; initial catalog=Auto2; user id=auto2; password=12345"

-received 'Unrecognized option '--connection''

>dotnet ef database update -c Auto2Context --configuration Release

  • no tables created in the prod db

2 Answers 2

1

Set ASPNETCORE_ENVIRONMENT environment variable before executing the command:

$env:ASPNETCORE_ENVIRONMENT='Production'

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

4 Comments

Unrecognized option '--environment' and Unrecognized option '-e'
also I see this: ASPNETCORE_ENVIRONMENT='Production' in a couple of different files. Launchsettings.json and launch.json.
As far as I know $env:ASPNETCORE_ENVIRONMENT='Production'should works see this
this doesn't seem correct as I would have to go into the file where this line exists and manually change it every time I go in-between dev and prod. That doesn't correct..
0

Here is what I used and it seems to work.

dotnet publish --configuration Release /p:EnvironmentName=Production

but this only builds the application. I had to run this command below to create a sql script to update the prod db.

dotnet ef migrations script -i -o "buildscript.sql" -c Auto2Context

Is this the best/correct way to push db changes to prod?

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.