working on MariaDB crash on server

This commit is contained in:
Philip Sargent 2022-07-21 21:01:57 +03:00
parent 312ecdcfe1
commit ce7dfd6510
2 changed files with 13 additions and 2 deletions

View File

@ -89,11 +89,15 @@ def reinit_db():
else:
print(" - No database file found: " + currentdbname + " ..continuing, will create it.\n")
else:
print(f" - Attempting to nuke : {currentdbname}\n")
# this is now completely failing to nuke MariaDB adequately, and it crashes when creating Area objects with a no null parent message
# when null parents are explciitly allowed in the model.
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(f" - Nuked : {currentdbname}\n")
print(" - Migrating: " + django.db.connections.databases['default']['NAME'])

View File

@ -12,6 +12,9 @@ from troggle.core.models.caves import Area, Cave, Entrance, CaveSlug, EntranceSl
'''Reads all the cave description data by parsing the xml files (stored as e.g. :EXPOWEB:/cave_data/1623-161.html )
and creating the various Cave, Entrance and necessary Area objects.
This is the first import that happens after the dabase is reinitialised.
So is the first thing that creates tables.
BUT in Django 2.0 and later we cannot do any queries on data we have just entered
because this is all happening inside one transaction. Bummer.
@ -184,8 +187,12 @@ def readcaves():
print(" - Creating Areas 1623 and 1626")
# This crashes on the server with MariaDB even though a null parent is explicitly allowed.
area_1623= Area.objects.create(short_name = "1623")
area_1626= Area.objects.create(short_name = "1626")
area_1623= Area.objects.create(short_name = "1623", parent=None)
print(" - Saving Area 1623")
area_1623.save()
area_1626= Area.objects.create(short_name = "1626", parent=None)
print(" - Saving Area 1626")
area_1626.save()
print (" - Setting pending caves")
# Do this first, so that these empty entries are overwritten as they get properly created.