Try to make mysql migration saner

This commit is contained in:
Griatch 2017-09-30 16:33:57 +02:00
parent 9f6f16fb7d
commit 1e16fda569

View file

@ -22,17 +22,15 @@ def _drop_table(db_cursor, table_name):
if _table_exists(db_cursor, table_name): if _table_exists(db_cursor, table_name):
if _ENGINE == "django.db.backends.mysql": if _ENGINE == "django.db.backends.mysql":
sql_drop = "SET FOREIGN_KEY_CHECKS=0;"\ db_cursor.execute("SET FOREIGN_KEY_CHECKS=0;")
"DROP TABLE {table};"\ db_cursor.execute("DROP TABLE {table};".format(table=table_name))
"SET FOREIGN_KEY_CHECKS=1;".format(table=table_name) db_cursor.execute("SET FOREIGN_KEY_CHECKS=1;")
elif _ENGINE == "postgresql_psycopg2": elif _ENGINE == "postgresql_psycopg2":
sql_drop = "ALTER TABLE {table} DISABLE TRIGGER ALL;"\ db_cursor.execute("ALTER TABLE {table} DISABLE TRIGGER ALL;".format(table=table_name))
"DROP TABLE {table};"\ db_cursor.execute("DROP TABLE {table};".format(table=table_name))
"ALTER TABLE {table} ENABLE TRIGGER ALL;".format(table=table_name) db_cursor.execute("ALTER TABLE {table} ENABLE TRIGGER ALL;".format(table=table_name))
else: # sqlite3, other databases else: # sqlite3, other databases
sql_drop = "DROP TABLE {table};".format(table=table_name) db_cursor.execute("DROP TABLE {table};".format(table=table_name))
db_cursor.execute(sql_drop)
def drop_tables(apps, schema_migrator): def drop_tables(apps, schema_migrator):