Skip to content

feat(database): support unsigned primary keys on MySQL - #2312

Open
sjorsvanleeuwen wants to merge 1 commit into
tempestphp:3.xfrom
sjorsvanleeuwen:feat/unsigned-primary-keys
Open

sjorsvanleeuwen wants to merge 1 commit into
tempestphp:3.xfrom
sjorsvanleeuwen:feat/unsigned-primary-keys

Conversation

@sjorsvanleeuwen

@sjorsvanleeuwen sjorsvanleeuwen commented Oct 9, 2026 •

Copy link
Copy Markdown

Summary

Adds an unsigned option to CreateTableStatement::primary() so integer primary keys can be created as INTEGER UNSIGNED on MySQL:

new CreateTableStatement('books')
    ->primary(unsigned: true)
    ->foreignId('author_id', constrainedOn: 'authors', unsigned: true)
    ->text('title');

MySQL rejects a foreign key whose column signedness differs from the referenced primary key, so belongsTo() and foreignId() also get an unsigned parameter that is passed through to the underlying integer column.

PostgreSQL and SQLite have no unsigned integer type. In line with #2295, the primary key output for those dialects is unchanged.

Changes

  • PrimaryKeyStatement: new unsigned flag; emits INTEGER UNSIGNED PRIMARY KEY AUTO_INCREMENT on MySQL.
  • CreateTableStatement: unsigned parameter on primary(), belongsTo() and foreignId().
  • Tests for unsigned primary keys and unsigned foreign keys across all dialects.
  • Docs: new "Using unsigned integers as primary keys" section.

All parameters default to false, so existing migrations are unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sjorsvanleeuwen

Copy link
Copy Markdown
Author

Feel free to move this to a discussion on Discord :)

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.

2 participants