RuntimeError: App registry isn't ready yet

The upcoming Django 1.7 has many interesting and welcomed changes. One of them is an update to how applications are loaded.

The relase notes also mention potential problems with these changes. I ran into RuntimeError: App registry isn't ready yet while using the self-contained tests approach, but the fix is as simple as mentioned in the relase notes.

import django
django.setup()

If your code needs to run on Django < 1.7 as well you could use

# Django 1.7
try:
    import django
    django.setup()
except AttributeError:
    pass

Update: Dieter's comment actually made me think about my code for a second and I'll be using something different:

import django
if hasattr(django, 'setup'):
    django.setup()

5 comments

  1. avatar
    wrote this comment on
    Well, that's the documented way to handle "it" (without the try, though). However, I had the problem that all test run ok when running through manage.py, but failed when started from PyCharm (all was well after I reverted to 1.6). I could not find the right place to put this code in that IDE . Reported it to JetBrains, got no solution.
  2. avatar
    wrote this comment on
    I use the try because the code I was working on supports Django 1.4 to 1.7. I'll update my post, thanks! I hope PyCharm will be updated, but I wouldn't know, I'm a happy vim user ;-)
  3. avatar
    wrote this comment on
    Hi Nicolas, Since you're targeting a known version of Django, you might want to be explicit about it, like: import django if django.VERSION >= (1, 7): django.setup()
  4. avatar
    wrote this comment on
    Hi zyegfryed, thanks for your suggestion!
  5. avatar
    wrote this comment on
    Thanks for this posting. I have had this issue for sometime now. The above code worked for me. However, I had to put these lines in my settings file almost at the end. Anywhere else, it will not work. But, it did work once plugged in at the end.

Reply

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo