class documentation

class BaseDatabaseSchemaEditor:

Known subclasses: django.db.backends.mysql.schema.DatabaseSchemaEditor, django.db.backends.oracle.schema.DatabaseSchemaEditor, django.db.backends.postgresql.schema.DatabaseSchemaEditor, django.db.backends.sqlite3.schema.DatabaseSchemaEditor

View In Hierarchy

This class and its subclasses are responsible for emitting schema-changing statements to the databases - model creation/removal/alteration, field renaming, index fiddling, and so on.
Method add​_constraint Add a constraint to a model.
Method add​_field Create a field on a model. Usually involves adding a column, but may involve adding a table instead (for M2M fields).
Method add​_index Add an index on a model.
Method alter​_db​_table Rename the table a model points to.
Method alter​_db​_tablespace Move a model's table between tablespaces.
Method alter​_field No summary
Method alter​_index​_together Deal with a model changing its index_together. The input index_togethers must be doubly-nested, not the single-nested ["foo", "bar"] format.
Method alter​_unique​_together Deal with a model changing its unique_together. The input unique_togethers must be doubly-nested, not the single-nested ["foo", "bar"] format.
Method create​_model Create a table and any accompanying indexes or unique constraints for the given model.
Method delete​_model Delete a model from the database.
Method execute Execute the given SQL statement, with optional parameters.
Method remove​_constraint Remove a constraint from a model.
Method remove​_field Remove a field from a model. Usually involves deleting a column, but for M2Ms may involve deleting a table.
Method remove​_index Remove an index from a model.
Static Method ​_effective​_default Undocumented
Method __enter__ Undocumented
Method __exit__ Undocumented
Method __init__ Undocumented
Method ​_alter​_column​_collation​_sql Undocumented
Method ​_alter​_column​_default​_sql Hook to specialize column default alteration.
Method ​_alter​_column​_null​_sql Hook to specialize column null alteration.
Method ​_alter​_column​_type​_sql Hook to specialize column type alteration for different backends, for cases when a creation type is different to an alteration type (e.g. SERIAL in PostgreSQL, PostGIS fields).
Method ​_alter​_field Perform a "physical" (non-ManyToMany) field update.
Method ​_alter​_many​_to​_many Alter M2Ms to repoint their to= endpoints.
Method ​_check​_sql Undocumented
Method ​_collate​_sql Undocumented
Method ​_column​_default​_sql Return the SQL to use in a DEFAULT clause. The resulting string should contain a '%s' placeholder for a default value.
Method ​_constraint​_names Return all constraint names matching the columns and conditions.
Method ​_create​_check​_sql Undocumented
Method ​_create​_fk​_sql Undocumented
Method ​_create​_index​_name Generate a unique name for an index/unique constraint.
Method ​_create​_index​_sql Return the SQL statement to create the index for one or several fields or expressions. sql can be specified if the syntax differs from the standard (GIS indexes, ...).
Method ​_create​_primary​_key​_sql Undocumented
Method ​_create​_unique​_sql Undocumented
Method ​_deferrable​_constraint​_sql Undocumented
Method ​_delete​_check​_sql Undocumented
Method ​_delete​_composed​_index Undocumented
Method ​_delete​_constraint​_sql Undocumented
Method ​_delete​_fk​_sql Undocumented
Method ​_delete​_index​_sql Undocumented
Method ​_delete​_primary​_key Undocumented
Method ​_delete​_primary​_key​_sql Undocumented
Method ​_delete​_unique​_sql Undocumented
Method ​_field​_became​_primary​_key Undocumented
Method ​_field​_indexes​_sql Return a list of all index SQL statements for the specified field.
Method ​_field​_should​_be​_altered Undocumented
Method ​_field​_should​_be​_indexed Undocumented
Method ​_fk​_constraint​_name Undocumented
Method ​_get​_index​_tablespace​_sql Undocumented
Method ​_index​_columns Undocumented
Method ​_index​_condition​_sql Undocumented
Method ​_index​_include​_sql Undocumented
Method ​_iter​_column​_sql Undocumented
Method ​_model​_indexes​_sql Return a list of all index SQL statements (field indexes, index_together, Meta.indexes) for the specified model.
Method ​_rename​_field​_sql Undocumented
Method ​_unique​_should​_be​_added Undocumented
Method ​_unique​_sql Undocumented
Method column​_sql Return the column definition for a field. The field must already have had set_attributes_from_name() called.
Method effective​_default Return a field's effective database default value.
Method prepare​_default Only used for backends which have requires_literal_defaults feature
Method quote​_name Undocumented
Method quote​_value No summary
Method remove​_procedure Undocumented
Method skip​_default Some backends don't accept default values for certain columns types (i.e. MySQL longtext and longblob).
Method skip​_default​_on​_alter Some backends don't accept default values for certain columns types (i.e. MySQL longtext and longblob) in the ALTER COLUMN statement.
Method table​_sql Take a model and return its table definition.
Class Variable sql​_alter​_column Undocumented
Class Variable sql​_alter​_column​_collate Undocumented
Class Variable sql​_alter​_column​_default Undocumented
Class Variable sql​_alter​_column​_no​_default Undocumented
Class Variable sql​_alter​_column​_not​_null Undocumented
Class Variable sql​_alter​_column​_null Undocumented
Class Variable sql​_alter​_column​_type Undocumented
Class Variable sql​_check​_constraint Undocumented
Class Variable sql​_constraint Undocumented
Class Variable sql​_create​_check Undocumented
Class Variable sql​_create​_column Undocumented
Class Variable sql​_create​_column​_inline​_fk Undocumented
Class Variable sql​_create​_fk Undocumented
Class Variable sql​_create​_index Undocumented
Class Variable sql​_create​_inline​_fk Undocumented
Class Variable sql​_create​_pk Undocumented
Class Variable sql​_create​_table Undocumented
Class Variable sql​_create​_unique Undocumented
Class Variable sql​_create​_unique​_index Undocumented
Class Variable sql​_delete​_column Undocumented
Class Variable sql​_delete​_constraint Undocumented
Class Variable sql​_delete​_index Undocumented
Class Variable sql​_delete​_procedure Undocumented
Class Variable sql​_delete​_table Undocumented
Class Variable sql​_rename​_column Undocumented
Class Variable sql​_rename​_table Undocumented
Class Variable sql​_retablespace​_table Undocumented
Class Variable sql​_unique​_constraint Undocumented
Class Variable sql​_update​_with​_default Undocumented
Instance Variable atomic Undocumented
Instance Variable atomic​_migration Undocumented
Instance Variable collect​_sql Undocumented
Instance Variable collected​_sql Undocumented
Instance Variable connection Undocumented
Instance Variable deferred​_sql Undocumented
def add_constraint(self, model, constraint):
Add a constraint to a model.
def add_field(self, model, field):
Create a field on a model. Usually involves adding a column, but may involve adding a table instead (for M2M fields).
def add_index(self, model, index):
Add an index on a model.
def alter_db_table(self, model, old_db_table, new_db_table):
Rename the table a model points to.
def alter_db_tablespace(self, model, old_db_tablespace, new_db_tablespace):
Move a model's table between tablespaces.
def alter_field(self, model, old_field, new_field, strict=False):
Allow a field's type, uniqueness, nullability, default, column, constraints, etc. to be modified. old_field is required to compute the necessary changes. If strict is True, raise errors if the old column does not match old_field precisely.
def alter_index_together(self, model, old_index_together, new_index_together):
Deal with a model changing its index_together. The input index_togethers must be doubly-nested, not the single-nested ["foo", "bar"] format.
def alter_unique_together(self, model, old_unique_together, new_unique_together):
Deal with a model changing its unique_together. The input unique_togethers must be doubly-nested, not the single-nested ["foo", "bar"] format.
def create_model(self, model):
def delete_model(self, model):
def execute(self, sql, params=()):
Execute the given SQL statement, with optional parameters.
def remove_constraint(self, model, constraint):
Remove a constraint from a model.
def remove_field(self, model, field):
Remove a field from a model. Usually involves deleting a column, but for M2Ms may involve deleting a table.
def remove_index(self, model, index):
Remove an index from a model.
@staticmethod
def _effective_default(field):

Undocumented

def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
def _alter_column_collation_sql(self, model, new_field, new_type, new_collation):
def _alter_column_default_sql(self, model, old_field, new_field, drop=False):

Hook to specialize column default alteration.

Return a (sql, params) fragment to add or drop (depending on the drop argument) a default to new_field's column.

def _alter_column_null_sql(self, model, old_field, new_field):

Hook to specialize column null alteration.

Return a (sql, params) fragment to set a column to null or non-null as required by new_field, or None if no changes are required.

def _alter_column_type_sql(self, model, old_field, new_field, new_type):

Hook to specialize column type alteration for different backends, for cases when a creation type is different to an alteration type (e.g. SERIAL in PostgreSQL, PostGIS fields).

Return a two-tuple of: an SQL fragment of (sql, params) to insert into an ALTER TABLE statement and a list of extra (sql, params) tuples to run once the field is altered.

def _alter_field(self, model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict=False):
def _alter_many_to_many(self, model, old_field, new_field, strict):
Alter M2Ms to repoint their to= endpoints.
def _check_sql(self, name, check):

Undocumented

def _collate_sql(self, collation):
def _column_default_sql(self, field):
Return the SQL to use in a DEFAULT clause. The resulting string should contain a '%s' placeholder for a default value.
def _constraint_names(self, model, column_names=None, unique=None, primary_key=None, index=None, foreign_key=None, check=None, type_=None, exclude=None):
Return all constraint names matching the columns and conditions.
def _create_check_sql(self, model, name, check):

Undocumented

def _create_fk_sql(self, model, field, suffix):

Undocumented

def _create_index_name(self, table_name, column_names, suffix=''):

Generate a unique name for an index/unique constraint.

The name is divided into 3 parts: the table name, the column names, and a unique digest and suffix.

def _create_index_sql(self, model, *, fields=None, name=None, suffix='', using='', db_tablespace=None, col_suffixes=(), sql=None, opclasses=(), condition=None, include=None, expressions=None):
Return the SQL statement to create the index for one or several fields or expressions. sql can be specified if the syntax differs from the standard (GIS indexes, ...).
def _create_primary_key_sql(self, model, field):

Undocumented

def _create_unique_sql(self, model, fields, name=None, condition=None, deferrable=None, include=None, opclasses=None, expressions=None):

Undocumented

def _deferrable_constraint_sql(self, deferrable):

Undocumented

def _delete_check_sql(self, model, name):

Undocumented

def _delete_composed_index(self, model, fields, constraint_kwargs, sql):
def _delete_constraint_sql(self, template, model, name):

Undocumented

def _delete_fk_sql(self, model, name):

Undocumented

def _delete_index_sql(self, model, name, sql=None):
def _delete_primary_key(self, model, strict=False):

Undocumented

def _delete_primary_key_sql(self, model, name):

Undocumented

def _delete_unique_sql(self, model, name, condition=None, deferrable=None, include=None, opclasses=None, expressions=None):

Undocumented

def _field_became_primary_key(self, old_field, new_field):

Undocumented

def _field_indexes_sql(self, model, field):
Return a list of all index SQL statements for the specified field.
def _field_should_be_altered(self, old_field, new_field):

Undocumented

def _fk_constraint_name(self, model, field, suffix):

Undocumented

def _get_index_tablespace_sql(self, model, fields, db_tablespace=None):

Undocumented

def _index_columns(self, table, columns, col_suffixes, opclasses):
def _index_condition_sql(self, condition):

Undocumented

def _index_include_sql(self, model, columns):

Undocumented

def _iter_column_sql(self, column_db_type, params, model, field, include_default):

Undocumented

def _model_indexes_sql(self, model):
Return a list of all index SQL statements (field indexes, index_together, Meta.indexes) for the specified model.
def _rename_field_sql(self, table, old_field, new_field, new_type):
def _unique_should_be_added(self, old_field, new_field):
def _unique_sql(self, model, fields, name, condition=None, deferrable=None, include=None, opclasses=None, expressions=None):

Undocumented

def column_sql(self, model, field, include_default=False):
def effective_default(self, field):
Return a field's effective database default value.
def prepare_default(self, value):
Only used for backends which have requires_literal_defaults feature
def quote_name(self, name):

Undocumented

def quote_value(self, value):
Return a quoted version of the value so it's safe to use in an SQL string. This is not safe against injection from user code; it is intended only for use in making SQL scripts or preparing default values for particularly tricky backends (defaults are not user-defined, though, so this is safe).
def remove_procedure(self, procedure_name, param_types=()):

Undocumented

def skip_default(self, field):
Some backends don't accept default values for certain columns types (i.e. MySQL longtext and longblob).
def skip_default_on_alter(self, field):
Some backends don't accept default values for certain columns types (i.e. MySQL longtext and longblob) in the ALTER COLUMN statement.
def table_sql(self, model):
Take a model and return its table definition.
sql_alter_column: str =

Undocumented

sql_alter_column_default: str =
sql_alter_column_no_default: str =
sql_check_constraint: str =

Undocumented

sql_constraint: str =

Undocumented

sql_create_check: str =

Undocumented

sql_create_column: str =
sql_create_fk: str =
sql_create_inline_fk =
sql_create_pk: str =
sql_create_table: str =

Undocumented

sql_create_unique: str =
sql_create_unique_index: str =

Undocumented

sql_delete_constraint: str =

Undocumented

sql_delete_procedure: str =
sql_rename_column: str =
sql_rename_table: str =
sql_retablespace_table: str =

Undocumented

sql_unique_constraint: str =

Undocumented

sql_update_with_default: str =

Undocumented

atomic =

Undocumented

atomic_migration =

Undocumented

collect_sql =

Undocumented

collected_sql: list =

Undocumented

connection =

Undocumented

deferred_sql: list =