我有两个新移民
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中如何处理?