'Rendering model states... DONE', fails

Hi,

I am following the tutorial in Django 4.2.11. In part 2 when I run:

python manage.py migrate

I get:

Operations to perform:
Apply all migrations: admin, auth, contenttypes, polls, sessions
Running migrations:
Applying polls.0001_initial… OK

I.e. the line with:

Rendering model states... DONE

is missing. When I try and inspect the database through the shell with:

Question.objects.all()

I get:

NameError: name 'Question' is not defined

Any help would be gratefully received.

Thanks.

Welcome @simpzoids-max !

This looks like you may be using the tutorial for Django 5.0 or newer. In older versions of Django, you need to import the model before using it.

Also, what version of Python are you running?

Hi Ken,

Thanks for the help.

I am running:

Python 3.12.3 (main, Nov  6 2025, 13:44:16) [GCC 13.3.0]

in mysite/polls/model.py I have:

from django.db import models

Regards,

Scott

Regarding the Rendering model states line, I also don’t get it when running migrate in a forward direction. However, if I run migrate to undo a migration, I do see it:

(p313-d52) tskww@MSI:~/git/mysite$ ./manage.py makemigrations polls
Migrations for 'polls':
  polls/migrations/0001_initial.py
    + Create model Question
    + Create model Choice

(p313-d52) tskww@MSI:~/git/mysite$ ./manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, polls, sessions
Running migrations:
  Applying polls.0001_initial... OK

(p313-d52) tskww@MSI:~/git/mysite$ ./manage.py migrate polls zero
Operations to perform:
  Unapply all migrations: polls
Running migrations:
  Rendering model states... DONE
  Unapplying polls.0001_initial... OK

I’ve tried digging into the migration code to see if I could understand why this is happening, but that’s a deeper rabbit hole than I can dig into at the moment.

@nessita , @jacobtylerwalls - Hate to tag y’all on this, but I can’t tell if this is a bug in the migrate command, a documentation issue, or something environmental causing it.

Oh and I have also selected the tutorial version 4.1 at the bottom of the tutorial page.

You need to import Question in the shell.

Quoting from the tutorial at Playing with the API, the very first command to be issued in the shell is:
from polls.models import Choice, Question # Import the model classes we just wrote.

Django 5.2 added automatic imports for the shell, making this unnecessary in current releases.

Hi Again,

I’ve created a virtual environment, complete with Django version 6.0 and it now works as described in the tutorial. Thanks for the help, particularly the inspiration to use the latest Django. I was tearing that last tuft of hair out.

Thanks again,

Scott

Hey Ken. Looks like we might be able to remove that line from the documentation.

Django 1.10.1 fixed a bug where the pre_migrate signal didn’t receive already applied migration states, and apparently calculating this before pre_migrate populates the cache in a way that that message never appears when running forward.

When running backward, the states have to be fetched again, so the message appears.

1 Like