Correct migrations to not re-remove fields.

This commit is contained in:
Griatch 2017-07-09 11:51:47 +02:00
parent c1326eaf23
commit 594500c4c7
5 changed files with 123 additions and 54 deletions

View file

@ -2,7 +2,18 @@
# Generated by Django 1.11.2 on 2017-07-06 20:41
from __future__ import unicode_literals
from django.db import migrations
from django.db import migrations, 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
class Migration(migrations.Migration):
@ -11,9 +22,15 @@ class Migration(migrations.Migration):
('objects', '0008_auto_20170705_1736'),
]
operations = [
migrations.RemoveField(
model_name='objectdb',
name='db_account',
),
]
db_cursor = connection.cursor()
if not _table_exists(db_cursor, "objectdb_db_player"):
# OBS - this is run BEFORE migrations are run!
operations = []
else:
operations = [
migrations.RemoveField(
model_name='objectdb',
name='db_player',
),
]