MariusG96
MariusG96

Reputation: 87

Migration to postgres doesn't work correctly

So I've built a very Asp.Net Core 3.0 MVC app, with some models and when I run the add-migration initial, it runs with no errors and it shows up in the solution explorer, but no changes occur in the actual PostgreSQL database.

I've noticed when I mess with the connection string, and put wrong stuff there, it only matters when I want to remove the migration, it gives no error when I want to add the migration.

I'm using .net core 3.0 , PostgreSQL 12.1.

ConfigureServices in Startup.cs:

services.AddEntityFrameworkNpgsql().AddDbContext<MyDbContext>(opt => opt.UseNpgsql(Configuration.GetConnectionString("DbConnection")));

Connection string in appsettings.json:

{
  "ConnectionStrings": {
    "DbConnection" :  "User ID =postgres;Password=pass;Server=localhost;Port=5432;Database=MyDb;Integrated Security = True; Pooling=true"
  },

DbContext:

    public class MyDbContext : DbContext
    {
        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }

        public DbSet<PirkVald> PirkValds { get; set; }
    }

Console output when running add-migration initial

Build started...
Build succeeded.
Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 3.1.0 initialized 'MyDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: None
To undo this action, use Remove-Migration.

Upvotes: 0

Views: 2690

Answers (1)

Ryan
Ryan

Reputation: 20116

You need to use Update-database to apply your migration and refresh your PostgreSQL database

Upvotes: 1

Related Questions