You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many models including those from 3rd party packages make use of model.ForeignKey fields which implicitly have indexes/keys. However, given that foreign keys are disabled, this means keys are disabled as well which can lead to severe performance penalties.
Unfortunately, I don't think there's an easy straightforward way like flipping a flag to make Django auto-create indexes. Only way I see is implementing a custom schema editor
fromdjango.db.backends.mysql.schemaimportDatabaseSchemaEditorclassCustomSchemaEditor(DatabaseSchemaEditor):
# some overrides/customizations hereclassDatabaseWrapper(MysqlDatabaseWrapper):
vendor='planetscale'features_class=DatabaseFeaturesSchemaEditorClass=CustomSchemaEditor
Users can manually specify indexes/keys but this is not ideal as this approach will not work well with external and 3rd party Django apps like django.contrib.auth
The text was updated successfully, but these errors were encountered:
1.0.6
3.9
OSX Monterey
Description
Turning off foreign key support in Django through
also disables any keys/index on columns
Many models including those from 3rd party packages make use of
model.ForeignKey
fields which implicitly have indexes/keys. However, given that foreign keys are disabled, this means keys are disabled as well which can lead to severe performance penalties.Consider the following relation (adapted from this Django doc example)
Using the
django-psdb-engine
driver, no key is created for theArticle.reporter
field which means running a query likewill result in a full table scan.
Fix:
Unfortunately, I don't think there's an easy straightforward way like flipping a flag to make Django auto-create indexes. Only way I see is implementing a custom schema editor
Users can manually specify indexes/keys but this is not ideal as this approach will not work well with external and 3rd party Django apps like
django.contrib.auth
The text was updated successfully, but these errors were encountered: