SQLite 错误 19:'FOREIGN KEY constraint failed'

SQLite Error 19: 'FOREIGN KEY constraint failed'

我正在开发 C# 应用程序,我正在使用 entity framework 来处理数据库。 我的项目中有以下数据库设计:

每当我尝试删除“租赁”中的一行时,我都会收到“外键约束失败”错误 table,我无法弄清楚为什么。

我的租金迁移 table 如下所示:

    migrationBuilder.CreateTable(
    name: "Rentals",
    columns: table => new
    {
        Id = table.Column<int>(type: "INTEGER", nullable: false)
            .Annotation("Sqlite:Autoincrement", true),
        CustomerId = table.Column<int>(type: "INTEGER", nullable: false),
        ProductsId = table.Column<int>(type: "INTEGER", nullable: false),
        DateAssigned = table.Column<DateTime>(type: "TEXT", nullable: false),
        Active = table.Column<bool>(type: "INTEGER", nullable: false)
    },
    constraints: table =>
    {
        table.PrimaryKey("PK_Rentals", x => x.Id);
        table.ForeignKey(
            name: "FK_Rentals_Customers_CustomerId",
            column: x => x.CustomerId,
            principalTable: "Customers",
            principalColumn: "Id");
        table.ForeignKey(
            name: "FK_Rentals_Products_ProductId",
            column: x => x.ProductId,
            principalTable: "Products",
            principalColumn: "Id");
    });    

modelBuilder.Entity("API.Entities.Rentals", b =>
    {
        b.HasOne("API.Entities.Customer", "Customer")
            .WithMany("Rentals")
            .HasForeignKey("CustomerId")
            .OnDelete(DeleteBehavior.NoAction)
            .IsRequired();

        b.HasOne("API.Entities.Product", "Product")
            .WithMany("Rentals")
            .HasForeignKey("ProductId")
            .OnDelete(DeleteBehavior.NoAction)
            .IsRequired();

        b.Navigation("Customer");

        b.Navigation("Product");
    });

对我做错了什么有什么想法吗?

好像是个小故障。

重新启动VS,之后错误没有再出现。