Fix migration edge cases with MySQL and PostgreSQL

This commit is contained in:
Griatch 2017-09-22 23:23:59 +02:00
parent fb773a9e75
commit 414bacf58b
7 changed files with 44 additions and 51 deletions

View file

@ -3,17 +3,11 @@
from __future__ import unicode_literals
from django.db import migrations, models, connection
from django.db import OperationalError
def _table_exists(db_cursor, tablename):
"Returns bool if table exists or not"
sql_check_exists = "SELECT * from %s;" % tablename
try:
db_cursor.execute(sql_check_exists)
return True
except OperationalError:
return False
return tablename in connection.introspection.table_names()
class Migration(migrations.Migration):

View file

@ -2,17 +2,12 @@
# Generated by Django 1.11.2 on 2017-07-06 20:41
from __future__ import unicode_literals
from django.db import migrations, OperationalError, connection
from django.db import migrations, connection
def _table_exists(db_cursor, tablename):
"Returns bool if table exists or not"
sql_check_exists = "SELECT * from %s;" % tablename
try:
db_cursor.execute(sql_check_exists)
return True
except OperationalError:
return False
return tablename in connection.introspection.table_names()
class Migration(migrations.Migration):