django_evolution.db.mysql

Evolution operations backend for MySQL/MariaDB.

Classes

EvolutionOperations(database_state[, connection])

Evolution operations for MySQL and MariaDB databases.

class django_evolution.db.mysql.EvolutionOperations(database_state, connection=<django.db.DefaultConnectionProxy object>)

Bases: BaseEvolutionOperations

Evolution operations for MySQL and MariaDB databases.

name = 'MySQL / MariaDB'

The name of the database type.

New in version 2.3.

get_field_type_allows_default(field)

Return whether default values are allowed for a field.

New in version 2.2.

Parameters:

field (django.db.models.Field) – The field to check.

Returns:

True if default values are allowed. False if they’re not.

Return type:

bool

get_change_column_type_sql(model, old_field, new_field)

Return SQL to change the type of a column.

New in version 2.2.

Parameters:
Returns:

The SQL statements for changing the column type.

Return type:

django_evolution.sql_result.AlterTableSQLResult

delete_column(model, f)
rename_column(model, old_field, new_field)

Rename the specified column.

This will rename the column through ALTER TABLE .. CHANGE COLUMN.

Any constraints on the column will be stashed away before the ALTER TABLE and restored afterward.

If the column has not actually changed, or it’s not a real column (a many-to-many relation), then this will return empty statements.

Parameters:
Returns:

The statements for renaming the column. This may be an empty list if the column won’t be renamed.

Return type:

django_evolution.db.sql_result.AlterTableSQLResult or list

set_field_null(model, field, null)
change_column_attr_max_length(model, mutation, field, old_value, new_value)

Returns the SQL for changing a column’s max length.

get_drop_index_sql(model, index_name)

Returns the database-specific SQL to drop an index.

This can be overridden by subclasses if they use a syntax other than “DROP INDEX <name>;”

get_change_unique_sql(model, field, new_unique_value, constraint_name, initial)

Returns the database-specific SQL to change a column’s unique flag.

This can be overridden by subclasses if they use a different syntax.

get_rename_table_sql(model, old_db_table, new_db_table)

Return SQL for renaming a table.

Parameters:
Returns:

The resulting SQL for renaming the table.

Return type:

django_evolution.db.sql_result.SQLResult

get_default_index_name(table_name, field)

Return a default index name for the database.

This will return an index name for the given field that matches what the database or Django database backend would automatically generate when marking a field as indexed or unique.

This can be overridden by subclasses if the database or Django database backend provides different values.

Parameters:
Returns:

The name of the index.

Return type:

str

get_indexes_for_table(table_name)

Return all known indexes on a table.

This is a fallback used only on Django 1.6, due to lack of proper introspection on that release.

Parameters:

table_name (unicode) – The name of the table.

Returns:

A dictionary mapping index names to a dictionary containing:

columns (list):

The list of columns that the index covers.

unique (bool):

Whether this is a unique index.

Return type:

dict