title: Cannot run migrate while using an existing database
body: <p>I am using Django3 and Python3 with the latest version to learn Django.</p>
  
  <p>I want to use <strong>an existing sqlite3 database</strong> for my django project. But I have problems while I was using the migrate command.</p>
  
  <p>I have done very few steps to my project so far:</p>
  
  <p><strong>1.</strong> use the venv, upgrade pip, install django,</p>
  
  <p><strong>2.</strong> generate a project,</p>
  
  <p><strong>3.</strong> insert an app, and add it into <code>INSTALLED_APPS</code>,</p>
  
  <p><strong>4.</strong> In the <code>settings.py</code>, I added the existing database into the <code>DATABASES</code> as follows.</p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.sqlite3',
          'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
      },
  
      'testdb': {
          'ENGINE': 'django.db.backends.sqlite3',
          'NAME': os.path.join(BASE_DIR, 'TestDB.sqlite3'),
      },
  }
  </code></pre>
  
  <ol start="5">
  <li>Then I use the method as here shows, to generate the models.py file.
  <a href="https://stackoverflow.com/questions/25697337/using-existing-database-in-django">Using existing database in Django</a></li>
  </ol>
  
  <p>The generated <code>models.py</code> looks like: (where I added the <code>max_length=25</code>)</p>
  
  <pre><code>from django.db import models
  
  
  class Stars(models.Model):
      actorname = models.CharField(db_column='ActorName', blank=True, null=True, max_length=25)
      realname = models.CharField(db_column='RealName', blank=True, null=True, max_length=25)
  
      class Meta:
          managed = False
          db_table = 'Stars'
  </code></pre>
  
  <p><strong>6.</strong> Then I run <code>python manage.py migrate</code> and/or <code>python manage.py makemigrations</code>, here I see the following errors: </p>
  
  <pre><code>    (venv) PS D:\Workfolder_Web\testProject\backend\project&gt; python .\manage.py migrate
      Traceback (most recent call last):
      File ".\manage.py", line 21, in &lt;module&gt;
          main()
      File ".\manage.py", line 17, in main
          execute_from_command_line(sys.argv)
      File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line 
          utility.execute()
      File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
          django.setup()
      File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\__init__.py", line 24, in setup
          apps.populate(settings.INSTALLED_APPS)
      File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
          app_config.import_models()
      File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\apps\config.py", line 211, in import_models
          self.models_module = import_module(models_module_name)
      File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
      File "&lt;frozen importlib._bootstrap&gt;", line 1014, in _gcd_import
      File "&lt;frozen importlib._bootstrap&gt;", line 991, in _find_and_load
      File "&lt;frozen importlib._bootstrap&gt;", line 975, in _find_and_load_unlocked
      File "&lt;frozen importlib._bootstrap&gt;", line 671, in _load_unlocked
      File "&lt;frozen importlib._bootstrap_external&gt;", line 779, in exec_module
      File "&lt;frozen importlib._bootstrap_external&gt;", line 916, in get_code
      File "&lt;frozen importlib._bootstrap_external&gt;", line 846, in source_to_code
      File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed
      ValueError: source code string cannot contain null bytes
  </code></pre>
  
  <p><strong>7.</strong> My database <code>TestDB.sqlite3</code> is very simple, it looks like: 
  <a href="https://i.stack.imgur.com/PRvtw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PRvtw.png" alt="enter image description here"></a></p>
  
  <p><strong>Question:</strong> How could I debug it? I am not using any bootstrap, urls, views or routers in my current codes.</p>
  
  <p>Thanks for the help!</p>