Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with apploading in Django 1.7 #1

Open
antonagestam opened this issue Sep 17, 2014 · 3 comments
Open

Issue with apploading in Django 1.7 #1

antonagestam opened this issue Sep 17, 2014 · 3 comments

Comments

@antonagestam
Copy link

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/apps/config.py", line 197, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/antonagestam/.virtualenvs/mcr-api/mcr/apps/like/models.py", line 21, in <module>
    connect_counter('like_count', Like.outfit)
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django_counter_field/counter.py", line 121, in connect_counter
    return Counter(counter_name, foreign_field, is_in_counter)
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django_counter_field/counter.py", line 30, in __init__
    self.connect()
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django_counter_field/counter.py", line 64, in connect
    self.validate()
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django_counter_field/counter.py", line 38, in validate
    self.counter_name
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/db/models/options.py", line 416, in get_field_by_name
    cache = self.init_name_map()
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/db/models/options.py", line 445, in init_name_map
    for f, model in self.get_all_related_m2m_objects_with_model():
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/db/models/options.py", line 563, in get_all_related_m2m_objects_with_model
    cache = self._fill_related_many_to_many_cache()
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/db/models/options.py", line 577, in _fill_related_many_to_many_cache
    for klass in self.apps.get_models():
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/utils/lru_cache.py", line 101, in wrapper
    result = user_function(*args, **kwds)
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/apps/registry.py", line 168, in get_models
    self.check_models_ready()
  File "/Users/antonagestam/.virtualenvs/mcr-api/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
@antonagestam
Copy link
Author

This might be solved by putting the call to connect_counter in some other place though.

@benosman
Copy link

Any ideas on where to put the call?

I was thinking AppConfig.ready() might be a good place.

@jneight
Copy link

jneight commented Oct 13, 2014

Yes, the correct place is inside the ready() function, this function gets called only when all the models are ready, see https://docs.djangoproject.com/en/dev/ref/applications/#django.apps.AppConfig.ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants