Runtime error:App registry isn't ready yet

后端 未结 3 1749
盖世英雄少女心
盖世英雄少女心 2020-12-28 08:56

I am trying to create a script that populates a database with test users. I am new to Django and Python. I keep on getting:

Runtime error: App registry isn\'         


        
相关标签:
3条回答
  • 2020-12-28 09:13

    I found out that if I run populate through the manage.py shell with the execfile() command then it runs properly. Everything needed to be setup before I start modifying the database or run outside code. Thanks to lanzz for the hint.

    0 讨论(0)
  • 2020-12-28 09:18

    This is a known and intended behaviour according to Django's 1.7 release notes, under the "startup sequence" clause:

    Another common culprit is django.contrib.auth.get_user_model(). Use the AUTH_USER_MODEL setting to reference the User model at import time.

    and that should do the trick

    for reference: https://docs.djangoproject.com/en/dev/releases/1.7/#app-loading-changes

    0 讨论(0)
  • 2020-12-28 09:19

    [django 1.7] The Standalone script you wish to run, import django and settings like below

    import os
    
    import django
    
    [...]
    
    
    if __name__ == '__main__':  
        os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
    
        django.setup()
    
    0 讨论(0)
提交回复
热议问题