SQLSTATE [23000]:违反完整性约束:尝试迁移时,laravel

时间:2018-07-25 10:39:24

标签: laravel-5.6

我有两个新移民

    Schema::create('courriers', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('link');
        $table->timestamps();
    });

还有这个

    Schema::table('shipments', function (Blueprint $table) {
        $table->integer('courrier_id')->unsigned()->index();
        $table->foreign('courrier_id')->references('id')->on('courriers')->onDelete('cascade')->onUpdate('cascade');
    });

请注意,我有很多表,包括shipments

但是在laravel迁移过程中,它会显示一条错误消息

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`databasename`.`#sql-2cc_99`, CONSTRAINT `shipments_courrier_id_foreign` FOREIGN KEY (`courrier_id`) REFERENCES `courriers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) (SQL: alter table `shipments` add constraint `shipments_courrier_id_foreign` foreign key (`courrier_id`) references `courriers` (`id`) on delete cascade on update cascade)

那是什么错误? 在laravel中如何处理?

0 个答案:

没有答案