Answer the question
In order to leave comments, you need to log in
Is an index required for an InnoDB MySQL foreign key?
In Yii2, when automatically generating a migration to create a table with a foreign key, a function is created with the following structure:
- create a table
- create an index on the foreign key field
- create a foreign key
The table is normally created without an index. Some advise not to create indexes when designing tables, only when accumulating several thousand records in a table to speed up queries.
Question 1: why did you build in index creation?
The migration rollback function has the reverse structure:
- delete the foreign key
- delete the index
- delete the table
Question 2: when a table is deleted, the index and the key are not deleted along with it? Or is it different in different DBMS?
Answer the question
In order to leave comments, you need to log in
Is an index required for an InnoDB MySQL foreign key?
Вопрос 1: зачем встроили создание индекса?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question