Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQLite不支持此迁移操作(';DropForeignKeyOperation';)_C#_Sqlite_Entity Framework Core - Fatal编程技术网

C# SQLite不支持此迁移操作(';DropForeignKeyOperation';)

C# SQLite不支持此迁移操作(';DropForeignKeyOperation';),c#,sqlite,entity-framework-core,C#,Sqlite,Entity Framework Core,我正在使用Asp.NETCore3.0和EFcore构建一个WebAPI。我使用代码优先的方法。 我用这个模型做了我的初始迁移 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 Ti

我正在使用Asp.NETCore3.0和EFcore构建一个WebAPI。我使用代码优先的方法。 我用这个模型做了我的初始迁移

  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; }
   }
后来,我在这个模型中添加了一个外键关系

  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; }
   }
当我在
PMC
上运行
addmigration
时,新的迁移将正确生成。但是,当我运行
更新数据库时,我得到以下错误:SQLite不支持此迁移操作(“DropForeignKeyOperation”)

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

解决方法(来源:)

您可以通过在迁移中手动编写代码以执行表重建来克服其中的一些限制。表重建包括重命名现有表、创建新表、将数据复制到新表以及删除旧表。您需要使用Sql(字符串)方法来执行其中一些步骤


编辑:根据@Shawn的指示,MSDN似乎已经过时,这是一种不当行为。相反,使用
Sql(string)
方法发出一个
altertable
语句,如文档所示。

接下来,建议的工作流程可能会严重破坏一切。有关进行更改的官方步骤,请参见。