【发布时间】:2018-01-22 22:18:24
【问题描述】:
我最近从表中删除了 ConversationId 列。当我开始调试我的服务并尝试保存时,我收到了一个错误:
列名“ConversationId”无效。
代码:
public class AstootContext : DbContext
{
public AstootContext(DbContextOptions<AstootContext> options)
: base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
public DbSet<ServiceRequest> ServiceRequests { get; set; }
}
我的实体看起来像这样:
public class ServiceRequest
{
public int Id { get; set; }
public int SenderUserId { get; set; }
public int PriceTypeId { get; set; }
public decimal Price { get; set; }
public bool IsAccepted { get; set; }
public DateTime Created { get; set; }
public int MessageId { get; set; }
}
所有对ConversationId 的引用均已从代码中删除,我已重新构建,但仍然出现此错误,我不明白为什么。
这是我的 SQL Server 表,您可以看到没有ConversationId:
是否有我需要删除的秘密缓存或我必须运行的东西来更新它?
【问题讨论】:
-
我想你可以尝试再次运行
migrations来更新修改后的列 -
@HaHoang 我目前没有使用迁移,我的数据库没有反映我的外键结构
-
听起来你有一个名为
Conversation的实体,它拥有像public ICollection<ServiceRequest> ServiceRequests { get; set; }这样的集合导航属性,不是吗? -
一旦你有了你的模型(来自现有数据库),你应该使用迁移来保持数据库与模型的任何更改同步。
-
@IvanStoev 就是这样,谢谢。如果您将其发布为答案,我会将其标记为正确
标签: c# entity-framework asp.net-core entity-framework-core