插入到microsoft sql server用户数据库失败

时间:2016-05-11 09:12:59

标签: sql-server yii2-advanced-app

为什么我不能为yii2应用程序添加多个用户?我正在使用microsoft sql server并且yii2 app的注册代码尚未更改。当用户表中没有记录时,我可以使用yii的注册页面添加用户。 这是数据库脚本

    USE [IBR]
GO

/****** Object:  Table [dbo].[user]    Script Date: 11/05/2016 16.51.02 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[user](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [username] [nvarchar](255) NOT NULL,
    [auth_key] [nvarchar](32) NOT NULL,
    [password_hash] [nvarchar](255) NOT NULL,
    [password_reset_token] [nvarchar](255) NULL,
    [email] [nvarchar](255) NOT NULL,
    [status] [smallint] NOT NULL DEFAULT ((10)),
    [created_at] [int] NOT NULL,
    [updated_at] [int] NOT NULL,
PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
    [password_reset_token] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
    [email] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
    [username] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

这是屏幕截图。error while signup for 2nd times

1 个答案:

答案 0 :(得分:0)

您的问题与[password_reset_token]列相似。

您对该列有唯一约束,但它允许NULL值,并且您不在此语句中插入数据,这就是为什么它将NULL视为重复键。您可以删除此字段上的唯一约束,也可以查看将唯一数据插入此字段。