无法插入Null

问题描述 投票:0回答:1

我正在使用代码优先迁移和使用apis post方法。但它给了我以下错误:

“InnerException”:{“Message”:“发生了错误。”,“ExceptionMessage”:“无法将值NULL插入列'AttendeeId',表'aspnet-WebApplication-20171216054501.dbo.Attendances';列不允许null.INSERT失败。语句已被终止。“,”异常类型“:”System.Data.SqlClient.SqlException“

出于某种原因,当我右键单击Attendee Id表时。它只给我刷新的选项。我无法进入物业!

sql visual-studio-2015 null ef-migrations
1个回答
2
投票

就像爵士爵士说的那样,如果它有约束,你应该检查你的AttendeeId。您应该包含标识以使其自动增加。例如,在您的create table中:

CREATE TABLE Attendances(
             AttendeeId INT IDENTITY(1,1) NOT NULL,
             [other column fields]. . .,

             CONSTRAINT PK_ATTENDANCES PRIMARY KEY(AttendeeId)
)

IDENTITY用于自动增量

© www.soinside.com 2019 - 2024. All rights reserved.