db_index=True doesn't create index

1,036 views
Skip to first unread message

Dario Bertini

unread,
Mar 1, 2011, 2:48:08 PM3/1/11
to Django users
this is my models.py:

from django.db import models
from django.db.models import Model
class Word(Model):
word = models.CharField(unique=True, db_index=True, max_length=30)
num = models.IntegerField(default=0, editable=False)


(actually it was much much more complicated, but i reduced it to this
and the problem still applies)

according to:

http://docs.djangoproject.com/en/dev/ref/models/fields/#db-index

when later running

python manage.py sqlindexes blog

it should output the create index statements for the relevant fields

but it doesn't work... with this bare models.py, it won't obviously
output anything else, but i also tried with the previous and bigger
models.py (with another model with a slugfield and a many-many
relationship with another model) and in that case it makes 2 create
index statement for these fields (but nothing for my Word.word field)

I also tried both with unique=True and without, since it seems that
that may be the cause of this problem:
http://stackoverflow.com/questions/2234423/django-db-index-issue

i also found some other people with apparently the same problem:

http://www.itarchive.org/7437/349

but i've found no related bug on the bug tracker (except for a not-
very-related and also old and fixed one: http://code.djangoproject.com/ticket/1828
)

my db is sqlite...

since i was fearing this may be related to the problem, i tried also
with mysql (but i never had to use mysql directly before)... upon
changing the relevant settings, though the sqlindexes command doesn't
change its ouput...

I also tried to look into the mysql db, with "show indexes from
blog_word" but i can't see to find anything different from the other
tables (also blog_tag for example, another model from the richer
models.py that shouldn't have any index at all, under index_type
lists: "BTREE"), then again i'm not used with mysql terminology

Łukasz Rekucki

unread,
Mar 1, 2011, 6:15:19 PM3/1/11
to django...@googlegroups.com
On 1 March 2011 20:48, Dario Bertini <berd...@gmail.com> wrote:
>
> but i've found no related bug on the bug tracker (except for a not-
> very-related and also old and fixed one: http://code.djangoproject.com/ticket/1828
> )

See http://code.djangoproject.com/ticket/14651

Also, from PostgreSQL's docs:

One should, however, be aware that there's no need to manually create
indexes on unique columns; doing so would just duplicate the
automatically-created index.

So there is just no need, to create the index - it's already there.

--
Łukasz Rekucki

Dario Bertini

unread,
Mar 4, 2011, 12:39:39 AM3/4/11
to Django users
On Mar 2, 12:15 am, Łukasz Rekucki <lreku...@gmail.com> wrote:
> Seehttp://code.djangoproject.com/ticket/14651
>
> Also, from PostgreSQL's docs:
>
> One should, however, be aware that there's no need to manually create
> indexes on unique columns; doing so would just duplicate the
> automatically-created index.
>
> So there is just no need, to create the index - it's already there.
>


Oh, ok...

I wonder if that also applies to sqlite

Thank you for the answer
Reply all
Reply to author
Forward
0 new messages