Hello again. OK, so I got my stack running for both MySQL and MariaDB. Long story short, both Django and database are in docker in their own separate containers. Again, Python 3.8.
MariaDB: 10.4.12
MySQL: 8.0.17
I performed the same tests as I did in my previous post.
Results
Passing
- Migrations: OK on both
- My own test script (not Django test suite) OK on Both
- Running my own database importer against MySQL, not MariaDB. It should be pointed out that I believe this has nothing to do with JSONField, as my importer tool doesn’t import any data that is stored as JSON, nor does it create any records in a Model which have a JSONField attribute
Failing
My Django test suite fails on both MariaDB and MySQL. Again, I think this is a problem with my stack, and not JSONField. It appears I need to install GDAL into my Django docker image, but that will have to wait for another day. It should be pointed out that my test cases are not failing, but rather a
======================================================================
ERROR: django.contrib.gis.utils (unittest.loader._FailedTest)
----------------------------------------------------------------------
Full stack trace below.
Interestingly enough, my data importer didn’t work with MariaDB. It failed about half way through and threw the following exception (again, this appears to have nothing to do with JSONField)
django.db.utils.OperationalError: (1267, "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='")
Summary
Given that both databases successfully handled my own custom testing script (again, not Django tests), I’m quite confident that JSONField worked as expected and as tested by my script.
I suspect that the failures are due to missing requirements and possibly a locale setting in my test stack. I’ll see if I can iron them out sometime in the near future.
Last, I will try and write some more advanced queries as suggested by Sage should I get the chance in the near future. Who knows, I might learning something!
Stack Traces
Django test cases failing
======================================================================
ERROR: django.contrib.gis.utils (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: django.contrib.gis.utils
Traceback (most recent call last):
File "/usr/local/lib/python3.8/unittest/loader.py", line 470, in _find_test_path
package = self._get_module_from_name(name)
File "/usr/local/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/code/django/contrib/gis/utils/__init__.py", line 4, in <module>
from django.contrib.gis.utils.ogrinfo import ogrinfo # NOQA
File "/code/django/contrib/gis/utils/ogrinfo.py", line 7, in <module>
from django.contrib.gis.gdal import DataSource
File "/code/django/contrib/gis/gdal/__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "/code/django/contrib/gis/gdal/datasource.py", line 39, in <module>
from django.contrib.gis.gdal.driver import Driver
File "/code/django/contrib/gis/gdal/driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "/code/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "/code/django/contrib/gis/gdal/libgdal.py", line 39, in <module>
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
Locale issue whilst importing data into MariaDB
Traceback (most recent call last):
File "/code/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/code/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 239, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1267, "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "importer.py", line 73, in <module>
main()
File "importer.py", line 63, in main
import_diagnostics(diagnostics, parameters, CASES)
File "/code/tools/importer/diagnostics.py", line 37, in import_diagnostics
base_values = create_base_blood_result(data)
File "/code/tools/importer/diagnostics.py", line 291, in create_base_blood_result
not BaseResult.objects.all()
File "/code/django/db/models/query.py", line 794, in exists
return self.query.has_results(using=self.db)
File "/code/django/db/models/sql/query.py", line 536, in has_results
return compiler.has_results()
File "/code/django/db/models/sql/compiler.py", line 1103, in has_results
return bool(self.execute_sql(SINGLE))
File "/code/django/db/models/sql/compiler.py", line 1133, in execute_sql
cursor.execute(sql, params)
File "/code/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/code/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/code/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/code/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/code/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/code/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/code/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 239, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1267, "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='")