0

I can't roll back migrations because a foreign id constraint fails despite using nullable() for the respective nullOnDelete()/onDelete('set null') columns schema.

I have the following line in notes table schema:

$table->foreignId('administrator_id')
    ->nullable()
    ->constrained()
    ->cascadeOnUpdate()
    ->onDelete('set null');

Migrations do run correctly, however, if I try to migrate:refresh it always fails with:

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (Connection: mysql, SQL: drop table if exists administrators)

I've tried nullOnDelete() instead of onDelete('set null'), same issue.

The Laravel framework version is 10.10, and the database I'm using is MariaDB 11.0.2.

Note that I don't want to cascade my entries on delete.

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
  • Have you tried disabling constraints during migrations? /E: And just seeing that you don't want to cascade on delete - which is fine - only the remark that this is what constraints are for. Double check for data that violate your current constraints, see Q&A: [Force InnoDB to recheck foreign keys on a table/tables?](https://stackoverflow.com/q/2250775/367456). – hakre Jul 30 '23 at 20:25

0 Answers0