title: Where in Django can I run startup code that requires models?
body: <p>On Django startup I need to run some code that requires access to the database. I prefer to do this via models.</p>
  
  <p>Here's what I currently have in <code>apps.py</code>:</p>
  
  <pre><code>from django.apps import AppConfig
  from .models import KnowledgeBase
  
  class Pqawv1Config(AppConfig):
      name = 'pqawV1'
  
      def ready(self):
          to_load = KnowledgeBase.objects.order_by('-timestamp').first()
          # Here should go the file loading code
  </code></pre>
  
  <p>However, this gives the following exception:</p>
  
  <p><code>django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.</code></p>
  
  <p>So is there a place in Django to run some startup code after the models are initialized?</p>