Question: I want to run [inspectdb](https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-inspectdb) against an Oracle database. The user account that I use is a read only user that owns 0 tables. It, however, has access to the schema that contains all the tables. How do I specify a schema when using `inspectdb`?

My command, currently, is: `python manage.py inspectdb --database "oradb" > test_model.py`

This only outputs a file with `from django.db import models`.

Answer: 
Just if someone comes upon this thread: Andy's suggestions + I've also changed the get\_relations method to get foreign keys in the generated source, works in 1.9.1:

```
    def get_relations(self, cursor, table_name):
    """
    Returns a dictionary of {field_name: (field_name_other_table, other_table)}
    representing all relationships to the given table.
    """
    table_name = table_name.upper()

    cursor.execute("""
        SELECT a.column_name, c_pk.table_name r_table_name, c_pk.constraint_name r_pk
          FROM all_cons_columns a
          JOIN all_constraints c ON a.owner = c.owner
                                AND a.constraint_name = c.constraint_name
          JOIN all_constraints c_pk ON c.r_owner = c_pk.owner
                                   AND c.r_constraint_name = c_pk.constraint_name
         WHERE c.constraint_type = 'R'
           AND a.table_name = %s""", [table_name])

    relations = {}
    for row in cursor.fetchall():
        relations[row[0].lower()] = (row[2].lower(), row[1].lower())
    return relations

```
My two cents in. (django version 1.9.7 + django GIS extension)

Following Andy and Mirek Simek suggestions I further modified:

added *'schemas'* in your db config in **settings.py**

```
    ...
    'oracle1': {
        'ENGINE': 'django.contrib.gis.db.backends.oracle',
        'NAME': 'dbname',
        'USER': 'dbuser',
        'PASSWORD': 'dbpass',
        'HOST': 'dbhostname',
        'PORT': 'dbport',
        'schemas': ['SCHEMANAME1', ....] #<-- this
    }, 
    ...

```

modified **get\_tables\_list** in this way:

```
def get_table_list(self, cursor):
    """
    Returns a list of table and view names in the current database.
    """
    cursor.execute("SELECT TABLE_NAME, 't' FROM USER_TABLES UNION ALL "
                   "SELECT VIEW_NAME, 'v' FROM USER_VIEWS")
    res = [TableInfo(row[0].lower(), row[1]) for row in cursor.fetchall()]

    schemas = self.connection.settings_dict.get('schemas')
    if schemas and len(schemas)>0:
        for s in schemas:
            cursor.execute("SELECT TABLE_NAME, 't' FROM ALL_TABLES WHERE OWNER = '%s'" %s)
            for row in cursor.fetchall():
                tbl_name, typ = '.'.join([s,row[0].lower()]), row[1]
                try:
                    # let us check for permission to query
                    cursor.execute("SELECT * FROM %s WHERE ROWNUM < 1" % tbl_name.upper())
                except DatabaseError, e:
                    pass
                else:
                    res.append(TableInfo(tbl_name, typ))
    return res

```

Cause I'm using gis I had to make a dirty patch (I don't know if it is needed due to database issue) to **django/contrib/gis/db/backends/oracle/introspection.py**

just added this at the end of **get\_geometry\_type**

```
    ...
        dim = len(dim)
        if dim != 2:
            field_params['dim'] = dim
    except:  # <-- this
        pass # <-- this
    finally:
        cursor.close()
    ...

```