Hi Mathew,

Thanks for your response. 

I did run makemigrations before running migration. There were no issues 
with those. But somehow the indexes were not showing on the tables when I 
ran SHOW INDEX from tablename;. That's the reason I was thinking of 
creating the indexes manually. 

I will look into RunSQL.

Thanks.

On Friday, October 5, 2018 at 7:12:18 PM UTC+5:30, Matthew Pava wrote:
>
> 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...@googlegroups.com <javascript:> [mailto:
> django...@googlegroups.com <javascript:>] *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...@googlegroups.com <javascript:>.
> To post to this group, send email to djang...@googlegroups.com 
> <javascript:>.
> 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/23c805c9-27c1-41f5-bc8e-1706dc4f038e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to