[英]SQLite Error 19: 'FOREIGN KEY constraint failed'
I am working on a C# application, and i am using entity framework to handle the database.我正在开发一个 C# 应用程序,并且我正在使用实体框架来处理数据库。 I have the following DB design in my project:
我的项目中有以下数据库设计:
I get a "Foreign Key Constraint Failed" error whenever i try do delete a row in the "rentals" table, and i cant figure out why.每当我尝试删除“rentals”表中的一行时,我都会收到“Foreign Key Constraint Failed”错误,但我不知道为什么。
My migration for the rentals table looks like this:我对出租表的迁移如下所示:
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");
});
Any ideas on what i am doing wrong?关于我做错了什么的任何想法?
Seem to be a glitch.好像是个毛病。
Restarted VS and afterwards the error didnt appear again.重新启动VS,之后错误不再出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.