简体   繁体   English

迁移到 postgres 无法正常工作

[英]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.所以我用一些模型构建了一个非常 Asp.Net Core 3.0 MVC 应用程序,当我运行add-migration initial ,它运行没有错误并且它显示在解决方案资源管理器中,但在实际的 PostgreSQL 中没有发生任何变化数据库。

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.我正在使用 .net core 3.0 ,PostgreSQL 12.1。

ConfigureServices in Startup.cs : Startup.cs ConfigureServices

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

Connection string in appsettings.json : 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运行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.

您需要使用Update-database来应用您的迁移并刷新您的 PostgreSQL 数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM