首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQLSTATE[23000]:完整性约束冲突: 1062键“”users_email_unique“”的条目“”rbuckridge@example.com“”重复

问SQLSTATE[23000]:完整性约束冲突: 1062键“”users_email_unique“”的条目“”rbuckridge@example.com“”重复
EN

Stack Overflow用户
提问于 2020-12-08 19:30:46
回答 1查看 271关注 0票数 0

以下是迁移代码:

代码语言:javascript
复制
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateUsersTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('users', function (Blueprint $table) {
                $table->id();
                $table->string('first_name');
                $table->string('last_name');
                $table->text('bio');
                $table->string('email')->unique();
                $table->timestamp('email_verified_at')->nullable();
                $table->string('password');
                $table->string('profile_picture');
                $table->rememberToken();
                $table->timestamps();
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('users');
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2020-12-08 20:03:07

迁移对您得到的错误的影响较小。这是因为在这一点上,错误指示rbuckridge@example.com已经存在于用户表中。这是通过->unique()方法实现的,该方法防止在相同的表列中重复输入相同的数据。

我的建议是先清空表格中的所有数据,然后重新输入邮件或使用其他邮件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65198106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档