Django ver 1.7 AppRegistryNotReady: Models aren't loaded yet

五迷三道 提交于 2019-12-23 09:04:44

问题


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() for ForeignKey related managers changed from a series of Model.save() calls to a single QuerySet.update() call. The change means that pre_save and post_save signals aren’t sent anymore. You can use the bulk=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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!