【发布时间】:2019-12-27 16:07:08
【问题描述】:
所以我用一些模型构建了一个非常 Asp.Net Core 3.0 MVC 应用程序,当我运行 add-migration initial 时,它运行没有错误,它显示在解决方案资源管理器中,但在实际的 PostgreSQL 数据库。
我注意到当我弄乱了连接字符串并在那里放了错误的东西时,只有当我想删除迁移时才重要,当我想添加迁移时它不会出错。
我正在使用 .net core 3.0 ,PostgreSQL 12.1。
ConfigureServices in Startup.cs:
services.AddEntityFrameworkNpgsql().AddDbContext<MyDbContext>(opt => opt.UseNpgsql(Configuration.GetConnectionString("DbConnection")));
appsettings.json中的连接字符串:
{
"ConnectionStrings": {
"DbConnection" : "User ID =postgres;Password=pass;Server=localhost;Port=5432;Database=MyDb;Integrated Security = True; Pooling=true"
},
数据库上下文:
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }
public DbSet<PirkVald> PirkValds { get; set; }
}
运行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.
【问题讨论】:
-
查看此文档npgsql.org/efcore
-
我跟着它,但它还是出现了错误。这个最简单的事情看起来太他妈的不可能了。
标签: c# asp.net asp.net-mvc postgresql asp.net-core