title: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. when i try to import models in consumers.py on heroku
body: <p>I run my <strong>django</strong> project on local which import models on consumers.py that work but when I deploy
  on <strong>heroku</strong> error occurred</p>
  <pre><code>2021-11-06T10:22:14.039525+00:00 app[web.1]: Traceback (most recent call last):
  2021-11-06T10:22:14.039542+00:00 app[web.1]:   File &quot;/app/.heroku/python/bin/daphne&quot;, line 8, in &lt;module&gt;
  2021-11-06T10:22:14.039607+00:00 app[web.1]:     sys.exit(CommandLineInterface.entrypoint())
  2021-11-06T10:22:14.039607+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/daphne/cli.py&quot;, line 170, in entrypoint
  2021-11-06T10:22:14.039690+00:00 app[web.1]:     cls().run(sys.argv[1:])
  2021-11-06T10:22:14.039697+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/daphne/cli.py&quot;, line 232, in run
  2021-11-06T10:22:14.039772+00:00 app[web.1]:     application = import_by_path(args.application)
  2021-11-06T10:22:14.039778+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/daphne/utils.py&quot;, line 12, in import_by_path
  2021-11-06T10:22:14.039824+00:00 app[web.1]:     target = importlib.import_module(module_path)
  2021-11-06T10:22:14.039830+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/importlib/__init__.py&quot;, line 127, in import_module
  2021-11-06T10:22:14.039892+00:00 app[web.1]:     return _bootstrap._gcd_import(name[level:], package, level)
  2021-11-06T10:22:14.039898+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1030, in _gcd_import
  2021-11-06T10:22:14.039963+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1007, in _find_and_load
  2021-11-06T10:22:14.040002+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 986, in _find_and_load_unlocked
  2021-11-06T10:22:14.040040+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 680, in _load_unlocked
  2021-11-06T10:22:14.040078+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 850, in exec_module
  2021-11-06T10:22:14.040124+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 228, in _call_with_frames_removed
  2021-11-06T10:22:14.040163+00:00 app[web.1]:   File &quot;/app/./spotgame/asgi.py&quot;, line 16, in &lt;module&gt;
  2021-11-06T10:22:14.040212+00:00 app[web.1]:     import spotifymusicgame.routing
  2021-11-06T10:22:14.040218+00:00 app[web.1]:   File &quot;/app/./spotifymusicgame/routing.py&quot;, line 3, in &lt;module&gt;
  2021-11-06T10:22:14.040261+00:00 app[web.1]:     from . import consumers
  2021-11-06T10:22:14.040268+00:00 app[web.1]:   File &quot;/app/./spotifymusicgame/consumers.py&quot;, line 59, in &lt;module&gt;
  2021-11-06T10:22:14.040324+00:00 app[web.1]:     from .models import roomInfo
  2021-11-06T10:22:14.040330+00:00 app[web.1]:   File &quot;/app/./spotifymusicgame/models.py&quot;, line 10, in &lt;module&gt;
  2021-11-06T10:22:14.040373+00:00 app[web.1]:     class songModel(models.Model):
  2021-11-06T10:22:14.040379+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/db/models/base.py&quot;, line 108, in __new__
  2021-11-06T10:22:14.040441+00:00 app[web.1]:     app_config = apps.get_containing_app_config(module)
  2021-11-06T10:22:14.040448+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/apps/registry.py&quot;, line 253, in get_containing_app_config
  2021-11-06T10:22:14.040534+00:00 app[web.1]:     self.check_apps_ready()
  2021-11-06T10:22:14.040540+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/apps/registry.py&quot;, line 136, in check_apps_ready
  2021-11-06T10:22:14.040599+00:00 app[web.1]:     raise AppRegistryNotReady(&quot;Apps aren't loaded yet.&quot;)
  2021-11-06T10:22:14.040617+00:00 app[web.1]: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
  </code></pre>
  <p>This is my <strong>consumers.py</strong></p>
  <pre><code>import json
  from channels.generic.websocket import AsyncWebsocketConsumer
  from channels.db import database_sync_to_async
  from .models import roomInfo
  class ChatConsumer(AsyncWebsocketConsumer):
      async def connect(self):
          self.room_name = self.scope['url_route']['kwargs']['room_name']
          self.room_group_name = 'chat_%s' % self.room_name
  
          # Join room group
          await self.channel_layer.group_add(
              self.room_group_name,
              self.channel_name
          )
  
          await self.accept()
  
      async def disconnect(self, close_code):
          # Leave room group
          await self.channel_layer.group_discard(
              self.room_group_name,
              self.channel_name
          )
  
      # Receive message from WebSocket
      async def receive(self, text_data):
          text_data_json = json.loads(text_data)
          message = text_data_json['message']
          username = text_data_json['username']
          print(username)
  
          # Send message to room group
          await self.channel_layer.group_send(
              self.room_group_name,
              {
                  'type': 'chat_message',
                  'message': message,
                  'username': username,
              }
          )
  
      # Receive message from room group
      async def chat_message(self, event):
          message = event['message']
          username = event['username']
          max_user = await self.max_users()
          print(max_user)
  
          # Send message to WebSocket
          await self.send(text_data=json.dumps({
              'message': message,
              'username': username,
          }))
      
      @database_sync_to_async
      def max_users(self):
          max_user = roomInfo.objects.get(id=1).max_player
          return max_user
  
  </code></pre>
  <p><strong>asgi.py</strong></p>
  <pre><code>import os
  import django
  
  from channels.auth import AuthMiddlewareStack
  from channels.routing import ProtocolTypeRouter, URLRouter
  from django.core.asgi import get_asgi_application
  import spotifymusicgame.routing
  
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'spotgame.settings')
  django.setup()
  application = ProtocolTypeRouter({
    &quot;http&quot;: get_asgi_application(),
    &quot;websocket&quot;: AuthMiddlewareStack(
          URLRouter(
              spotifymusicgame.routing.websocket_urlpatterns
          )
      ),
  })
  
  </code></pre>
  <p><strong>wsgi.py</strong></p>
  <pre><code>import os
  
  from django.core.wsgi import get_wsgi_application
  
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'spotgame.settings')
  
  application = get_wsgi_application()
  
  </code></pre>
  <p><strong>settings.py</strong></p>
  <pre><code>
  ASGI_APPLICATION = &quot;spotgame.routing.application&quot;
  
  CHANNEL_LAYERS = {
      &quot;default&quot;: {
          &quot;BACKEND&quot;: &quot;channels_redis.core.RedisChannelLayer&quot;,
          &quot;CONFIG&quot;: {
              &quot;hosts&quot;: [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
          },
      },
  }
  </code></pre>
  <p><strong>Procfile</strong></p>
  <pre><code>release: python manage.py migrate
  web: daphne spotgame.asgi:application --port $PORT --bind 0.0.0.0 -v2
  worker: python manage.py runworker channels --settings=spotgame.settings -v2
  </code></pre>
  <p>I assume <strong>heroku</strong> can't load models in time.
  Please let me know if it is unclear what I am asking or if I need to show any other files.</p>