Skip to content

Align component_checks.component_id with legacy components.id on MySQL#380

Draft
jbrooksuk with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-mysql-migration-issue
Draft

Align component_checks.component_id with legacy components.id on MySQL#380
jbrooksuk with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-mysql-migration-issue

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

MySQL 8.0.16+ rejects the component_checks foreign key because foreignId() creates BIGINT UNSIGNED while the legacy components.id column is INT UNSIGNED. SQLite did not surface this because it does not enforce FK integer-type compatibility the same way.

  • Migration fix

    • Replace foreignId('component_id') with unsignedInteger('component_id')
    • Keep the foreign key explicit so component_checks.component_id matches components.id
  • Regression coverage

    • Add a focused migration test that compiles the schema with Laravel's MySQL grammar
    • Assert the generated DDL uses INT UNSIGNED for component_id, guarding against future reintroduction of foreignId()
  • Result

    • php artisan migrate can create component_checks on modern MySQL versions without FK type mismatch errors
Schema::create('component_checks', function (Blueprint $table) {
    $table->id();
    $table->unsignedInteger('component_id');
    // ...

    $table->foreign('component_id')
        ->references('id')
        ->on('components')
        ->cascadeOnDelete();
});

Copilot AI changed the title [WIP] Fix migration failure on MySQL due to FK type mismatch Align component_checks.component_id with legacy components.id on MySQL Jul 8, 2026
Copilot AI requested a review from jbrooksuk July 8, 2026 10:56
@jbrooksuk

Copy link
Copy Markdown
Member

@copilot fix the broken tests

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the broken tests

Fixed in 45f9e8d. The test had two constructor signature issues:

  1. MySqlGrammar() requires a Connection in L13.x prefer-lowest
  2. Blueprint($connection, 'table') is invalid - Blueprint takes ($table, ?Closure, $prefix)

Changed to proper signatures: new MySqlGrammar($connection) and new Blueprint('component_checks').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants