Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create database index on foreignkey field #293

Open
heybuddy opened this issue Jun 20, 2024 · 1 comment
Open

Cannot create database index on foreignkey field #293

heybuddy opened this issue Jun 20, 2024 · 1 comment

Comments

@heybuddy
Copy link

heybuddy commented Jun 20, 2024

I'm experiencing the same problem described in this blog post: https://mathieulamiot.com/my-feedbacks-on-using-cockroachdb-for-a-data-intensive-django-service/

Basically, creating a foreignkey field does not create a database index, even if db_index=True is specified. The workaround described above is to make a RunSQL migration to manually create the index for every field, but it would be better to respect the db_index argument.

I am using cockroachdb 22.1.22 and django-cockroachdb==3.2.2.

Thanks!

@timgraham
Copy link
Collaborator

This is because ForeignKey defaults to db_index=True. That makes sense on databases where foreign keys are automatically indexed, but not for CockroachDB.

Did you try using Meta.indexes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants