Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django ver 1.7 AppRegistryNotReady: Models aren't loaded yet

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', '[email protected]', '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?

like image 566
searching_for_truth Avatar asked Sep 19 '14 17:09

searching_for_truth


1 Answers

I suggest doing this before your code above:

import django
django.setup()

Does that fix it?

like image 68
Nathan Stocks Avatar answered Nov 02 '22 06:11

Nathan Stocks