这是我的迁移:
public function up()
{
Schema::table('payments', function($table)
{
$table->dropColumn('invoice_id');
});
}
public function down()
{
Schema::table('payments',function (Blueprint $table){
$table->unsignedInteger('invoice_id')->index();
$table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade');
});
}
当我运行 php artisan migrate:rollback 它给了我这个异常:
[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`invoiceninja`.`#sq
l-418_46`, CONSTRAINT `payments_invoice_id_foreign` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`) ON DELETE CASCADE) (SQL: alter
table `payments` add constraint `payments_invoice_id_foreign` foreign key (`invoice_id`) references `invoices` (`id`) on delete cascade)
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`invoiceninja`.`#sq
l-418_46`, CONSTRAINT `payments_invoice_id_foreign` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`) ON DELETE CASCADE)
谁能帮我 ?