django-fcm
django-fcm copied to clipboard
Models aren't loaded yet.
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
Hello @dvkovner you can try
DeviceModel = apps.get_model('<app_name>', '<model_name>')
to import the mode instead of importing directly
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.