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

Models aren't loaded yet. #30

Open
dvkovner opened this issue Dec 18, 2016 · 2 comments
Open

Models aren't loaded yet. #30

dvkovner opened this issue Dec 18, 2016 · 2 comments

Comments

@dvkovner
Copy link

Hello! I'm using django-fcm 0.1.1 with Django 1.10. When I've imported DeviceSerializer in my models.py file, I've got the error "django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.". The problem was resolved by moving import statement from the top of models.py to the method. Maybe, it isn't an issue, but there are no similar problems with other serializers.

Traceback (most recent call last):
File "C:\Source\hospital\env\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(args, **kwargs)
File "C:\Source\hospital\env\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Source\hospital\env\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
six.reraise(
exception)
File "C:\Source\hospital\env\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Source\hospital\env\lib\site-packages\django_init
.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Source\hospital\env\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Source\hospital\env\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\Lib\importlib_init_.py", line 37, in import_module
import(name)
File "C:\Source\hospital\hospital\models.py", line 15, in
from fcm.serializers import DeviceSerializer
File "C:\Source\hospital\env\lib\site-packages\fcm\serializers.py", line 3, in
Device = get_device_model()
File "C:\Source\hospital\env\lib\site-packages\fcm\utils.py", line 15, in get_device_model
return apps.get_model(model)
File "C:\Source\hospital\env\lib\site-packages\django\apps\registry.py", line 194, in get_model
self.check_models_ready()
File "C:\Source\hospital\env\lib\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.

@Chitrank-Dixit
Copy link
Owner

Hello @dvkovner you can try

DeviceModel = apps.get_model('<app_name>', '<model_name>')

to import the mode instead of importing directly

@dvkovner
Copy link
Author

dvkovner commented Dec 22, 2016

The problem isn't in the model. It is in the serializer. When I try to import DeviceSerializer on the top of my models.py file, I get the error: "django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.".

When this row of code is placed on the top of models.py, I can't run my app: "from fcm.serializers import DeviceSerializer". I've resolved it by moving this import to the method inside my class in models.py.

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

2 participants