class documentation

class BaseDatabaseIntrospection:

Known subclasses: django.db.backends.dummy.base.DatabaseIntrospection, django.db.backends.mysql.introspection.DatabaseIntrospection, django.db.backends.oracle.introspection.DatabaseIntrospection, django.db.backends.postgresql.introspection.DatabaseIntrospection, django.db.backends.sqlite3.introspection.DatabaseIntrospection

View In Hierarchy

Encapsulate backend-specific introspection utilities.
Method __init__ Undocumented
Method django​_table​_names Return a list of all table names that have associated Django models and are in INSTALLED_APPS.
Method get​_constraints Retrieve any constraints or keys (unique, pk, fk, check, index) across one or more columns.
Method get​_field​_type Hook for a database backend to use the cursor description to match a Django field type to a database column.
Method get​_key​_columns Backends can override this to return a list of: (column_name, referenced_table_name, referenced_column_name) for all key columns in given table.
Method get​_migratable​_models Undocumented
Method get​_primary​_key​_column Return the name of the primary key column for the given table.
Method get​_relations Return a dictionary of {field_name: (field_name_other_table, other_table)} representing all relationships to the given table.
Method get​_sequences Return a list of introspected sequences for table_name. Each sequence is a dict: {'table': <table_name>, 'column': <column_name>}. An optional 'name' key can be added if the backend supports named sequences.
Method get​_table​_description Return a description of the table with the DB-API cursor.description interface.
Method get​_table​_list Return an unsorted list of TableInfo named tuples of all tables and views that exist in the database.
Method identifier​_converter Apply a conversion to the identifier for the purposes of comparison.
Method installed​_models Return a set of all models represented by the provided list of table names.
Method sequence​_list Return a list of information about all DB sequences for all models in all apps.
Method table​_names No summary
Class Variable data​_types​_reverse Undocumented
Instance Variable connection Undocumented
def __init__(self, connection):

Undocumented

def django_table_names(self, only_existing=False, include_views=True):

Return a list of all table names that have associated Django models and are in INSTALLED_APPS.

If only_existing is True, include only the tables in the database.

def get_constraints(self, cursor, table_name):

Retrieve any constraints or keys (unique, pk, fk, check, index) across one or more columns.

Return a dict mapping constraint names to their attributes, where attributes is a dict with keys:

  • columns: List of columns this covers
  • primary_key: True if primary key, False otherwise
  • unique: True if this is a unique constraint, False otherwise
  • foreign_key: (table, column) of target, or None
  • check: True if check constraint, False otherwise
  • index: True if index, False otherwise.
  • orders: The order (ASC/DESC) defined for the columns of indexes
  • type: The type of the index (btree, hash, etc.)

Some backends may return special constraint names that don't exist if they don't name constraints of a certain type (e.g. SQLite)

def get_field_type(self, data_type, description):

Hook for a database backend to use the cursor description to match a Django field type to a database column.

For Oracle, the column data_type on its own is insufficient to distinguish between a FloatField and IntegerField, for example.

def get_key_columns(self, cursor, table_name):
Backends can override this to return a list of:
(column_name, referenced_table_name, referenced_column_name)

for all key columns in given table.

def get_migratable_models(self):

Undocumented

def get_primary_key_column(self, cursor, table_name):
def get_relations(self, cursor, table_name):
def get_sequences(self, cursor, table_name, table_fields=()):
Return a list of introspected sequences for table_name. Each sequence is a dict: {'table': <table_name>, 'column': <column_name>}. An optional 'name' key can be added if the backend supports named sequences.
def identifier_converter(self, name):

Apply a conversion to the identifier for the purposes of comparison.

The default identifier converter is for case sensitive comparison.

def installed_models(self, tables):
Return a set of all models represented by the provided list of table names.
def sequence_list(self):
Return a list of information about all DB sequences for all models in all apps.
def table_names(self, cursor=None, include_views=False):
Return a list of names of all tables that exist in the database. Sort the returned table list by Python's default sorting. Do NOT use the database's ORDER BY here to avoid subtle differences in sorting order between databases.
connection =

Undocumented