我在EF中有一些插入表格的代码。我在CreatedBy列上有一个外键
C#代码
INSERT [dbo].[ProductPackages]([ProductSizeId], [PackageSizeId],
[CarrierCode], [SAPId], [CaseUPCSupplierPack], [CreatedBy], [CreatedDate],
[UpdatedBy], [UpdatedDate], [IsActive])
VALUES (@0, @1, NULL, NULL, @2, @3, NULL, @4, NULL, @5)
SELECT [Id]
FROM [dbo].[ProductPackages]
WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()
-- @0: '631' (Type = Int32)
-- @1: '46' (Type = Int32)
-- @2: 'fsdfds' (Type = AnsiString, Size = 50)
-- @3: '0' (Type = Int32)
-- @4: '0' (Type = Int32)
-- @5: 'True' (Type = Boolean)
INSERT语句与FOREIGN KEY约束冲突" FK_ProductPackages_ToCreated"。冲突发生在数据库"定价",表" dbo.Users",列' Id'。
以下是DB上的SQL生成
CREATE TABLE [dbo].[ProductPackages]
(
[Id] INT NOT NULL PRIMARY KEY identity,
[ProductSizeId] int not null,
[PackageSizeId] int not null,
[CarrierCode] varchar(50) NULL ,
[SAPId] INT,
[CaseUPCSupplierPack] VARCHAR(50),
[CreatedBy] int NOT NULL DEFAULT 1,
[CreatedDate] DATETIME DEFAULT getdate(),
[UpdatedBy] int NOT NULL DEFAULT 1,
[UpdatedDate] DATETIME DEFAULT getdate(),
[IsActive] BIT NOT NULL DEFAULT 1,
CONSTRAINT [FK_ProductPackages_ToProductSize] FOREIGN KEY ([ProductSizeId]) REFERENCES [ProductSizes]([Id]),
CONSTRAINT [FK_ProductPackages_ToPackageSize] FOREIGN KEY ([PackageSizeId]) REFERENCES [PackageSizes]([Id]),
CONSTRAINT [FK_ProductPackages_ToCreated] FOREIGN KEY ([CreatedBy]) REFERENCES [Users]([Id]),
CONSTRAINT [FK_ProductPackages_ToUpdated] FOREIGN KEY ([UpdatedBy]) REFERENCES [Users]([Id]),
)
正如您所看到的,我正在提供' 1'作为CreatedBy字段,并且Id存在于用户表中。我在这里缺少什么?
表格脚本
$('.canvas-off-toggle').click(function(e) {
e.preventDefault();
$('.a-class').toggleClass('is-active');
$('.another-class').toggleClass('is-active');
document.body.style.overflowY = "hidden";
});