c# - 无法在 postgresql 中创建表
问题描述
我在 pgAdmin 中手动删除了两个表,现在我想再次创建它。我做了一些更改,应用了迁移,但未创建此表。无法理解,为什么?
当我发送将项目添加到此表的请求时,我收到错误:关系“ProductsComparsion”不存在
public class Product
{
public int Id { get; set; }
public ICollection<ProductToCompare> ProductsToCompare { get; set; } //! Added
}
// I want to create tables for two models below
public class ProductComparsion
{
public int Id { get; set; }
public int? UserId { get; set; }
public Guid SessionId { get; set; }
public int CategoryId { get; set; }
public DateTime Created { get; set; }
public ICollection<ProductToCompare> ProductsToCompare { get; set; }
}
public class ProductToCompare
{
public int ProductComparsionId { get; set; }
public ProductComparsion ProductComparsion { get; set; }
public int ProductId { get; set; }
public Product Product { get; set; }
}
AppDbContextModelProvider
modelBuilder.Entity<ProductComparsion>(typeBuiler =>
{
typeBuiler.ToTable(nameof(AppDbContext.ProductsComparsion));
typeBuiler.HasKey(z => z.Id);
});
modelBuilder.Entity<ProductToCompare>(typeBuilder =>
{
typeBuilder.HasKey(z => new { z.ProductId, z.ProductComparsionId });
typeBuilder.ToTable(nameof(AppDbContext.ProductsToCompare));
typeBuilder.HasOne(z => z.ProductComparsion).WithMany(z => z.ProductsToCompare).HasForeignKey(z => z.ProductComparsionId);
typeBuilder.HasOne(z => z.Product).WithMany(z => z.ProductsToCompare).HasForeignKey(z => z.ProductId);
});
解决方案
推荐阅读
- javascript - Javascript:如何单击按钮,显示某些内容,然后再次单击并返回默认值?
- woocommerce - 为其他类型的用户复制 woocomerce 产品不起作用
- linux-kernel - 处理器间通信驱动,用户空间交互
- python - Python:设施位置问题->如何获得每个设施的总成本和总客户数
- typescript - Switch in TypeScript does not narrow actions
- javascript - 选项卡未在 HTMLButtonElement.onclick 中定义
- javascript - Chrome 上的 Serviceworker 不显示 HTTP 基本身份验证对话框?
- javascript - 当 opacity:0 或 visibility:hidden 时,不应用类
- .net-core - 在 AceClient 中使用网络 IP 地址作为数据源时出错
- java - 如何使用模型和适配器类在折线图中传递值