Skip to content
Discussion options

You must be logged in to vote

What is the bug?

The schema builder does not keep a copy of the model instance. So when calling constrained() it tries to guess the table from the foreign key name.

As you are using a custom foreign key name (due to a self-referencing foreign key), it correctly tries to guess from that name.

From the docs:

... while the constrained method will use conventions to determine the table and column being referenced. If your table name does not match Laravel's conventions, you may manually provide it to the constrained method.

Reference: https://laravel.com/docs/11.x/migrations#foreign-key-constraints

When using a custom foreign key, just provide the table name to the constrained() method.

Als…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@raghed-kahil
Comment options

@raghed-kahil
Comment options

@rodrigopedra
Comment options

Answer selected by raghed-kahil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #53121 on October 14, 2024 01:29.