title: GeoDjango inspectdb with multiple databases
body: <p>I'm trying to run <code>inspectdb</code> on a PostgreSQL DB with Postgis.</p>
  
  <p>To generate the model for a postgresql view, I found <a href="https://stackoverflow.com/a/47679397/3976696">here</a> that I should use the command:</p>
  
  <pre><code>python manage.py inspectdb --database my_schema my_view&gt; my_view_legacy.py
  </code></pre>
  
  <p>But because of PostGIS, <code>inspectdb</code> also tries to access a view in another schema, which raises the following error when it encounters a field of type <code>geometry</code> in <code>my_view</code>:</p>
  
  <pre><code>django.db.utils.ProgrammingError: relation "geometry_columns" does not exist
  LINE 1: SELECT "coord_dimension", "srid", "type" FROM "geometry_colu...
  </code></pre>
  
  <p>This seems like a <a href="https://en.wikipedia.org/wiki/Catch-22_(logic)" rel="nofollow noreferrer">catch-22</a>: if I specify the database name so that <code>inspectdb</code> knows which view to inspect, it cannot find find the <code>geometry_columns</code> view in the <code>public</code> schema. But if I don't specify any database name, it cannot find <code>my_view</code> in the first place. </p>
  
  <p>Is there any solution to this?</p>
  
  <p>My database schemas are defined as:</p>
  
  <pre><code>DATABASES = {
  
      'default': 
              {
              },
  
      'public': 
              {
              'ENGINE': 'django.db.backends.postgresql_psycopg2',
              'OPTIONS': {
                              'options': '-c search_path=public'
                          },
              'NAME': 'my_db',
              'USER': secrets.USER,
              'PASSWORD': secrets.PASSWORD,
              'HOST': 'my.host.addr',
              'PORT': '5432',
              },
  
      'my_schema': 
              {
              'ENGINE': 'django.contrib.gis.db.backends.postgis', 
              'OPTIONS': {
                              'options': '-c search_path=my_schema'
                          },
              'NAME': 'my_db',
              'USER': secrets.USER,
              'PASSWORD': secrets.PASSWORD,
              'HOST': 'my.host.addr',
              'PORT': '5432',
              },    
  }
  </code></pre>