0

I've been reading the documentation to use a postgres database from my asp.net core project here:

https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

I've been running the commands:

dotnet ef database add InitialMigration dotnet ef database update

To define my local database. My question now is, how do I go about actually getting this ready for production? I'm thinking I'd like to wrap up the database creation in a docker container, where I can just supply the connection string, and when the container runs, it will create the database. I'm not really sure on how I go about this as the docs don't really make it clear what I need to be able to run the above commands. Do I actually need my uncompiled code in the container, or can I just add the migration and copy over the migration files at build time? If I do that, how do I go about supplying the connection string at runtime?

Andy
  • 3,228
  • 8
  • 40
  • 65
  • As long as your connectionstring is right, you should be fine just deploying the application. EF executes migrations automatically if i'm not mistaking. look here if you want to set it up explicitly: https://stackoverflow.com/questions/36265827/entity-framework-automatic-apply-migrations – Glenn van Acker Nov 13 '19 at 12:27
  • 1
    Migrations are not executed automatically. Your application is not going to work until you run the migrations on the production database. You can use `DbContext.Database.Migrate();` at runtime to apply the migrations or create a sql script using `Script-Migration` in Package-Manager Console and then apply the script to the db manually. – bnu Nov 14 '19 at 07:21

0 Answers0