TypeError: 'class Meta' got invalid attribute(s): indexes

1,666 views
Skip to first unread message

Dennis Kornbluh

unread,
Aug 22, 2016, 10:58:51 AM8/22/16
to Django users
Going through the Django tutorial, now at part 5, section "Running tests". Followed the directions precisely, copy/pasted to create polls/test.py, After running

$ python manage.py test polls

got a stacktrace (http://dpaste.com/2XP5QZ7) ending with TypeError: 'class Meta' got invalid attribute(s): indexes

Totally stumped. Everything has worked up to this point. 



Markus Holtermann

unread,
Aug 22, 2016, 11:07:54 AM8/22/16
to django...@googlegroups.com
Hi Dennis,

"indexes" is a new thing in the upcoming Django version. I'm fairly
certain that you accidentially used Django's development version at some
point while going through the tutorial.

Could you please paste your models.py and the migration files Django
created for you when you ran "manage.py makemigrations".

/Markus

On Sun, Aug 21, 2016 at 11:16:44PM -0700, Dennis Kornbluh wrote:
>Going through the Django tutorial
><https://docs.djangoproject.com/en/1.10/intro/tutorial05/>, now at part 5,
>--
>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.
>To post to this group, send email to django...@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/4725f223-8a5e-4177-b5d2-b92d0fd416db%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

Tim Graham

unread,
Aug 22, 2016, 11:12:22 AM8/22/16
to Django users
What Django version are you using? Meta.indexes is a new feature in Django 1.11 -- are you using it in your models?

Dennis Kornbluh

unread,
Aug 22, 2016, 12:01:23 PM8/22/16
to Django users
Hi Markus,

Yes, you're right. When I started the tutorial I got the latest source from github, but then I uninstalled and reinstalled 1.10 using pip. Something remained from 1.11, perhaps in the database?

import datetime

from django.db import models
from django.utils import timezone

class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

    def __str__(self):
        return self.question_text

    def was_published_recently(self):
        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

    def __str__(self):
        return self.choice_text

----
# -*- coding: utf-8 -*-
# Generated by Django 1.11.dev20160816211734 on 2016-08-18 04:05
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Choice',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('choice_text', models.CharField(max_length=200)),
                ('votes', models.IntegerField(default=0)),
            ],
            options={
                'indexes': [],
            },
        ),
        migrations.CreateModel(
            name='Question',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('question_text', models.CharField(max_length=200)),
                ('pub_date', models.DateTimeField(verbose_name='date published')),
            ],
            options={
                'indexes': [],
            },
        ),
        migrations.AddField(
            model_name='choice',
            name='question',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Question'),
        ),
    ]

Aha! Should've grepped the whole project for indexes. How do I "undo" this?

Thanks,
Dennis

Dennis Kornbluh

unread,
Aug 22, 2016, 12:07:13 PM8/22/16
to django...@googlegroups.com
I think I solved the problem by commenting out the two options elements. If there's a better way to address this, please let me know.

Thanks,
Dennis

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/udRJ1G9laj0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages