SQL Server中因为主键无法插入数据(column does not allow nulls)

错误如下:

SQL Server中因为主键无法插入数据(column does not allow nulls)

错误原因是int类型的主键没有设置为自增。

Step1:在VS中打开服务资源管理器,找到对应的表,打开表定义

SQL Server中因为主键无法插入数据(column does not allow nulls)

Step2:将主键设置为自增,并更新数据库即可。

SQL Server中因为主键无法插入数据(column does not allow nulls)

Step3:重新运行项目,就可以发现错误没有啦。