Automatic/Implicit Index Creation for Foreign Keys (PostgreSQL and SQLite)) #54343
Unanswered
mathiasgrimm
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
In MySQL, foreign key columns automatically receive corresponding indexes. However, PostgreSQL requires explicit index creation for foreign key columns. While this behavior is inherent to PostgreSQL and not related to Laravel, we can enhance Laravel's handling of this database-specific difference.
Despite our Schema DDL abstraction layer, migrations can produce different database structures when run on MySQL versus PostgreSQL/SQLite due to how each database handles index creation for foreign keys.
Proposed Solution
Add a configuration option in Laravel to automatically create indexes for PostgreSQL foreign key columns, making the behavior consistent with other supported databases.
Configuration
Current Usage
Desired Usage
Implementation Considerations
A mechanism should be provided to override the automatic index creation when needed
References
MySQL
https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html
SQLite
https://www.sqlite.org/foreignkeys.html
PostgreSQL
https://www.postgresql.org/docs/current/indexes-unique.html
https://www.postgresql.org/docs/current/ddl-constraints.html
Beta Was this translation helpful? Give feedback.
All reactions