SQLSTATE[23000]: 无法在对象中插入重复键行

SQLSTATE[23000]: Cannot insert duplicate key row in object

当我尝试将新列插入 SQL 服务器数据库时,出现以下错误。

SQLSTATE[23000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot insert duplicate key row in object 'dbo.users' with unique index 'users_api_token_unique'. The duplicate key value is (). (SQL: insert into [users] ([name], [email], [password], [updated_at], [created_at]) values (ibramin salah, ibra@gmail.com, y$laopDTNj9Ddzr4cf4a4ctuxYwra5raqm8TXXBS.Rc2wBH2mnf.cJG, 2020-08-07 08:57:49.077, 2020-08-07 08:57:49.077))

Table 架构

Schema::create('users', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->boolean('adminCreation')->default(0);
    $table->rememberToken();
    $table->timestamps();
});

我正在使用 Laravel 5.8 和 PHP 版本 7.4.4。

您正在尝试将新的 record/row 插入到电子邮件中具有唯一约束(进而创建唯一索引)的 table。

由于这似乎是唯一约束中包含的唯一列,这意味着某个电子邮件值只能在 table 中插入一次。否则它不会是该列的唯一值。

根据您的 table 列名称,这看起来像是某种用户注册,这似乎是所需的行为。这意味着您的数据库中可能只有一些需要清除的测试数据。或者在开发过程中暂时放弃唯一性约束,或者不断补充新的电子邮件值。