Lumen Migration - Foreign Id With A Table Name That Isn't The Plural Of The Local Key
How can I create a Lumen migration with a column that references a table that has an unrelated name to the column name?
Example:
The following would throw an error that user_destinations can't be found.
$table->foreign('user_destination')->references('id')->on('locations');
or
$table->foreignId('warehouse_isle_shelf_id')->constrained();
The intention here is for it to look for warehouse_isles
instead of warehouse_isle_shelves
or warehouse_isle_shelfs
as I'm not sure how Lumen handles plurals for words who's plurals aren't just taking the singular form and appending an s
.
Answer
Your code here should work because you have referenced the table name locations
:
$table->foreign('user_destination')->references('id')->on('locations');
But the second line is asking Laravel to guess the name. Here's the relevant part talking about it in the documentation:
The foreignId method is an alias for unsignedBigInteger while the constrained method will use convention to determine the table and column name being referenced. If your table name does not match the convention, you may specify the table name by passing it as an argument to the constrained method:
$table->foreignId('user_id')->constrained('users');
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms