Hi,
I’m using Django 2.0 and PostgreSQL 9.something, but my tables do have indexes. 
 Did you run the makemigrations command before running the migrate command?

Also, you can modify the database that Django uses however you want with some 
caveats.  Anyway, you can add views and modify columns and add constraints in 
the database.  I do have a suggestion that if you do that, you create your own 
migration files with the RunSQL command so that you can be able to recreate the 
database structure and keep track of your modifications.

So, in your case, if you really want to add an index manually, create a blank 
migration file, and add this operation:
migrations.RunSQL(“CREATE INDEX my_cool_looking_index USING BTREE ON 
appname_modelname (my_cool_looking_field)”)

https://docs.djangoproject.com/en/1.11/ref/django-admin/#django-admin-makemigrations

https://docs.djangoproject.com/en/1.11/ref/migration-operations/#runsql

Good luck!

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Web Architect
Sent: Friday, October 5, 2018 7:14 AM
To: Django users
Subject: db_index=True not creating indexes

Hi,

We are using django for our ecommerce website.

I am facing a strange issue. I was trying to index a field in a table and 
hence, set db_index=True in the field declaration. I ran migrations but when I 
checked the indexes for the table, the index for the field wasn't there. There 
were also few foreign key fields but no indexes for them as well. The migration 
didn't throw any error. Hence, I am a bit perplexed.

Would appreciate if anyone could help me with the above.

Also, can I create indexes directly in the database (not via django)? Will that 
have any issue in Django.

I am using Django 1.11. MySQL is 5.6.

Thanks.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2b5b6f3d-a704-46f6-9506-c0a47cdead26%40googlegroups.com<https://groups.google.com/d/msgid/django-users/2b5b6f3d-a704-46f6-9506-c0a47cdead26%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bb23ce00c45142e1b55bfd8d104f0497%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Reply via email to