c# - SQLite 不支持此迁移操作 ('DropForeignKeyOperation' )

标签 c# sqlite entity-framework-core

我正在使用带有 EFcore 的 Asp.Net core 3.0 构建 Web API。我正在使用代码优先的方法。
我使用此模型进行了初始迁移

  public class Group {
    [Key]
    public int Id{get;set;}
    public string Title { get; set; }
   }

后来我给这个模型加了外键关系
  public class Group {
    [Key]
    public int Id{get;set;}
    public string Title { get; set; }

    [ForeignKey("UserId")]
    public User User { get; set; }
    public int UserId { get; set; }
   }

当我运行 Add-Migration <migrationName> 时,新的迁移会正确生成在 PMC .但是当我运行 update-database我收到此错误:SQLite 不支持此迁移操作 ('DropForeignKeyOperation')

最佳答案

这是一个 documented SQLite 数据库提供程序的限制:

解决方法(来源:MSDN)

You can workaround some of these limitations by manually writing code in your migrations to perform a table rebuild. A table rebuild involves renaming the existing table, creating a new table, copying data to the new table, and dropping the old table. You will need to use the Sql(string) method to perform some of these steps.



编辑 :按照@Shawn 的指示,MSDN 似乎已过时,这是一种不当行为。而是使用 Sql(string)发出 ALTER TABLE 的方法记录在案的声明 here .

关于c# - SQLite 不支持此迁移操作 ('DropForeignKeyOperation' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61032270/

相关文章:

c# - 在 Azure 存储 Blob 上使用 .Net Core 和 C# 将图像序列转换为 MP4 文件

database - SQLite如何求一个数的幂

SQLite:如何更新另一个的值?

android - 在 Android 应用程序中使用类而不是 sqlite

c# - 实体核心 2.0.3 异常 : must be reducible node

c# - C# 中的远程主机强制关闭现有连接

c# - ASP.NET Core - 如何在另一个 Controller 中重用在一个 Controller 中创建的方法?

c# - WCF 使用 MSMQ 发布/订阅

c# - 通过 IOptions 配置 EF Core 上下文

entity-framework - Azure 上的 Entity Framework 核心 : Update-Database parameter –ConnectionString does not work