Skip to content

migrate fails on MySQL: component_checks.component_id (BIGINT) FK references components.id (INT) #366

Description

@siebsie23

Summary

php artisan migrate fails on MySQL when running the new Component Monitoring migration (2025_09_14_000000_create_component_checks_table.php, added in #211). The foreign key column component_checks.component_id is created as BIGINT UNSIGNED (via foreignId()), but the referenced components.id is INT UNSIGNED (created long ago via increments('id')). MySQL 8.0.16+/9.x strictly requires matching integer types for foreign keys and rejects this with error 3780. The mismatch is invisible on SQLite, which doesn't enforce FK column-type compatibility.

Environment

  • cachethq/core: dev-main (reproduced with component_checks migration as of Component Monitoring #211; still present after Advanced Component Group Ordering #212)
  • Database: MySQL 9.7 (also affects MySQL 8.0.16+; older MySQL/MariaDB were lenient and did not error)
  • PHP: 8.2+
  • Install: from source (composer install + php artisan migrate)

Steps to reproduce

  1. Configure .env with DB_CONNECTION=mysql against a MySQL 8.0.16+ / 9.x server.
  2. php artisan migrate (or php artisan migrate:fresh).
  3. Migration fails at 2025_09_14_000000_create_component_checks_table.php.

Actual error

SQLSTATE[HY000]: General error: 3780 Referencing column 'component_id' and referenced
column 'id' in foreign key constraint 'component_checks_component_id_foreign' are
incompatible. (Connection: mysql, SQL: alter table `component_checks` add constraint
`component_checks_component_id_foreign` foreign key (`component_id`) references
`components` (`id`) on delete cascade)

Root cause

database/migrations/2015_01_05_201444_CreateComponentsTable.php:

$table->increments('id');   // INT UNSIGNED

database/migrations/2025_09_14_000000_create_component_checks_table.php:

$table->foreignId('component_id')->constrained('components')->cascadeOnDelete();  // BIGINT UNSIGNED

foreignId() produces BIGINT UNSIGNED, while components.id remains INT UNSIGNED. MySQL requires the FK column and the referenced column to be the same integer type/size, so the constraint creation fails. This appears to be masked when running against SQLite, which does not enforce FK column-type compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions