c# - 迁移到 postgres 无法正常工作
问题描述
因此,我构建了一个非常 Asp.Net Core 3.0 MVC 应用程序,其中包含一些模型,当我运行时add-migration initial
,它运行时没有错误,并且显示在解决方案资源管理器中,但实际 PostgreSQL 数据库中没有发生任何变化。
我注意到当我弄乱连接字符串并在那里放错东西时,它只在我想删除迁移时才重要,当我想添加迁移时它不会出错。
我正在使用 .net core 3.0 , PostgreSQL 12.1。
ConfigureServices
在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.
解决方案
您需要使用Update-database
来应用您的迁移并刷新您的 PostgreSQL 数据库
推荐阅读
- arrays - 在具有关联输入数组时检查验证错误并在 Blade 模板中提取错误
- visual-studio - SSRS 报告数据在报告服务器与本地预览上看起来不同
- python - Python(VS Code)中的模块'cassandra.cluster'中没有名称'Cluster'
- javascript - Javascript scrollIntoView(); 不加载
- tmux - TMUX 添加了一个我无法关闭的窗口
- javascript - 如何在网页中显示设备连接或断开连接
- python - 多元线性回归 100% 准确度
- css - Bootstrap 3.3.1 正在影响整个页面的字体
- python - 查询 SQLite3 时 Python 中的字符串格式
- .net - 当我尝试将客户端 .net 应用程序与 OPC 服务器连接时,来自 HRESULT 的异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE))