Chitrank-Dixit / django-fcm

Django FCM provides firebase cloud messaging to android or ios support for django apps
https://django-fcm.readthedocs.io/en/latest/
MIT License
54 stars 28 forks source link

Models aren't loaded yet. #30

Open dvkovner opened 7 years ago

dvkovner commented 7 years ago

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 commented 7 years ago

Hello @dvkovner you can try

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

to import the mode instead of importing directly

dvkovner commented 7 years ago

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.