Replies: 1 comment
-
This is not true, Laravel doesn't create an index for the foreign constraint, MySQL does! MySQL requires indexes on foreign keys and referenced keys, and an index is created on the referencing table automatically if it does not exist.
Not a good idea, because it's MySQL specific, for example PostgreSQL doesn't create an index / doesn't need an index on foreign constraint.
Didn't understand your question! What we can improve here?We can improve $table->dropForeign(['notification']); // drop any foreign key constraint of `['notification']` column not just `test_notification_foreign`
$table->dropIndex(['notification']); // drops any indexes of `['notification']` column not just `test_notification_index` |
Beta Was this translation helpful? Give feedback.
-
Dear Community and Developers,
Thank you very much for the ineffably marvelous project! ✨
May I ask regarding the method
dropForeign
? Currently, when we create a new foreign, Laravel creates a correspondingindex
for the constraint. For example, let's check a quick case.Case
Initial state of table "test'
Create a foreign for table "notifications"
As we see, alongside the foreign constraint
test_notification_foreign
there an additional indextest_notification_foreign
has just been automatically created. The rationale behind the creation is fairly clear, since the performance difference with an without such an index may be crucial.Drop the created foreign
As we see, the foreign constraint
test_notification_foreign
got removed but the indextest_notification_foreign
. This may require an additional explicit command to be executed after thedropForeign
:Question
dropForeign
(e.g.index
of typestring|bool
wherestring
would define an explicit name, andbool
- an self-generated by the framework)?framework/src/Illuminate/Database/Schema/Blueprint.php
Lines 1633 to 1640 in 1d7e000
Best and kind regards
Related
- Dropping column with foreign key Laravel error
Beta Was this translation helpful? Give feedback.
All reactions