diff --git a/databaseReset.py b/databaseReset.py index a89f910..7134242 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -85,19 +85,21 @@ def reinit_db(): else: print(" - No database file found: " + currentdbname + " ..continuing, will create it.\n") else: - cursor = django.db.connection.cursor() - cursor.execute("DROP DATABASE %s" % currentdbname) - cursor.execute("CREATE DATABASE %s" % currentdbname) - cursor.execute("ALTER DATABASE %s CHARACTER SET=utf8" % currentdbname) - cursor.execute("USE %s" % currentdbname) + with transaction.atomic(): + cursor = django.db.connection.cursor() + cursor.execute("DROP DATABASE %s" % currentdbname) + cursor.execute("CREATE DATABASE %s" % currentdbname) + cursor.execute("ALTER DATABASE %s CHARACTER SET=utf8" % currentdbname) + cursor.execute("USE %s" % currentdbname) print(" - Migrating: " + django.db.connections.databases['default']['NAME']) - management.call_command('makemigrations','core', interactive=False) - management.call_command('makemigrations','flatpages', interactive=False) - management.call_command('migrate', interactive=False) - management.call_command('migrate','core', interactive=False) - management.call_command('migrate','flatpages', interactive=False) + with transaction.atomic(): + management.call_command('makemigrations','core', interactive=False) + management.call_command('makemigrations','flatpages', interactive=False) + management.call_command('migrate', interactive=False) + management.call_command('migrate','core', interactive=False) + management.call_command('migrate','flatpages', interactive=False) print(" - done migration on: " + settings.DATABASES['default']['NAME']) print("users in db already: ",len(User.objects.all()))