我正在使用带有 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/