Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

->index()->constrained() vs ->constrained()->index() produces different results for foreign keys #54789

Closed
WarenN opened this issue Feb 25, 2025 · 1 comment

Comments

@WarenN
Copy link

WarenN commented Feb 25, 2025

Laravel Version

11

PHP Version

8.3

Database Driver & Version

SQLite

Description

Hello Laravel team,

I'm using Laravel (version X) and noticed a difference in behavior depending on the order in which I call ->index() and ->constrained() on a foreign ID column.

Example 1: This creates an index on main_activity_domain_id:

$table->foreignId('main_activity_domain_id')
->index()
->constrained()
->restrictOnDelete()
->restrictOnUpdate();

Example 2: This does not create an index on main_activity_domain_id:

$table->foreignId('main_activity_domain_id')
->constrained()
->index()
->restrictOnDelete()
->restrictOnUpdate();

I would have expected both code snippets to create an index on the foreign key column. Is this an intentional difference, or might it be a bug in how Laravel processes these chained methods?

Thanks for taking a look!

Steps To Reproduce

Migrations

@WarenN
Copy link
Author

WarenN commented Feb 25, 2025

sorry, notified in doc

@WarenN WarenN closed this as completed Feb 25, 2025
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

No branches or pull requests

1 participant