问题
I am trying to work through the authentication tutorials to make sure everything works as expected. I entered the following code.
>>> from django.contrib.auth.models import User
>>> user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
>>> user.last_name = 'Lennon'
>>> user.save()
and I get the error
AppRegistryNotReady: Models aren't loaded yet.
I see from the release notes
The default implementation of
remove()
forForeignKey
related managers changed from a series ofModel.save()
calls to a singleQuerySet.update()
call. The change means thatpre_save
andpost_save
signals aren’t sent anymore. You can use thebulk=False
keyword argument to revert to the previous behaviour.
So I presume it is a foreign key issue.
My question is, where do I use the bulk=False
attribute or is there another solution?
回答1:
I suggest doing this before your code above:
import django
django.setup()
Does that fix it?
来源:https://stackoverflow.com/questions/25939719/django-ver-1-7-appregistrynotready-models-arent-loaded-yet