在生产中插入语句

Insert statement in production

我目前有一个应用程序在本地运行完美。当我将我的应用程序移至生产环境时,我收到以下错误。

Cannot insert the value NULL into column 'ID', table
'StarVote.dbo.Voters'; column does not allow nulls. INSERT fails. The
statement has been terminated.

当我在本地执行操作时,一切正常。知道为什么会这样吗?每当我在我的数据库中创建任何对象时,我都会收到上面列出的错误。我的应用程序允许我创建一个具有内置身份的用户,但我的其他对象似乎破坏了我的应用程序。本地工作正常。生产失败。

我假设 id 应该是一个递增的值。

你需要设置这个,否则如果你有一个不可为空的列,没有默认值,如果你不提供任何值就会出错。

要在 SQL Server Management Studio 中设置自动增量:

  1. 在设计
  2. 中打开您的table
  3. Select 您的列并转到列属性
  4. 在 Indentity Specification 下,设置 (Is Identity)=Yes and Indentity 增量=1