django-fcm icon indicating copy to clipboard operation
django-fcm copied to clipboard

Models aren't loaded yet.

Open dvkovner opened this issue 8 years ago • 2 comments

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.

dvkovner avatar Dec 18 '16 11:12 dvkovner

Hello @dvkovner you can try

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

to import the mode instead of importing directly

Chitrank-Dixit avatar Dec 22 '16 08:12 Chitrank-Dixit

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.

dvkovner avatar Dec 22 '16 08:12 dvkovner