django-toosimple-q
django-toosimple-q copied to clipboard
Problems with migrations
Hi,
Im trying execute migrations to MySQL but get this errors:
Applying toosimpleq.0004_auto_20200507_1339...Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
File "/opt/homebrew/lib/python3.10/site-packages/django/db/backends/mysql/base.py", line 76, in execute
return self.cursor.execute(query, args)
File "/opt/homebrew/lib/python3.10/site-packages/MySQLdb/cursors.py", line 179, in execute
res = self._query(mogrified_query)
File "/opt/homebrew/lib/python3.10/site-packages/MySQLdb/cursors.py", line 330, in _query
db.query(q)
File "/opt/homebrew/lib/python3.10/site-packages/MySQLdb/connections.py", line 261, in query
_mysql.connection.query(self, query)
MySQLdb.OperationalError: (1071, 'Specified key was too long; max key length is 3072 bytes')
and
Applying toosimpleq.0011_workerstatus...Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/django/db/backends/utils.py", line 103, in _execute
return self.cursor.execute(sql)
File "/opt/homebrew/lib/python3.10/site-packages/django/db/backends/mysql/base.py", line 76, in execute
return self.cursor.execute(query, args)
File "/opt/homebrew/lib/python3.10/site-packages/MySQLdb/cursors.py", line 179, in execute
res = self._query(mogrified_query)
File "/opt/homebrew/lib/python3.10/site-packages/MySQLdb/cursors.py", line 330, in _query
db.query(q)
File "/opt/homebrew/lib/python3.10/site-packages/MySQLdb/connections.py", line 261, in query
_mysql.connection.query(self, query)
MySQLdb.OperationalError: (1071, 'Specified key was too long; max key length is 3072 bytes')
The problems is related with this:
field=models.CharField(max_length=1024, unique=True),
Can you fix this?
Thanks.
I put 512 only to execute migration and bypass the error. But if i try change it by database from 512 to 1024, i get the same error:
The varchar from toosimpleq_taskexec works with 1024, but because it is not a unique key.
Hmm I wasn't aware of this limitation for mysql. It's indeed documented here: https://docs.djangoproject.com/en/5.2/ref/databases/#character-fields
I don't like the idea of simpliy changing this to 255 as it wouldn't be backwards compatible. Also for now tests don't run against mysql, and I have no idea how it behaves in regard of transactions/locking, so I wouldn't advise using this package with a mysql backend anyways.
Are you able/willing to contribute supporting mysql as a backend ? Otherwise, we could document that only sqlite and postgres are supported for now.
You can launch a version 2 changing it to 255, because it is documented in Django docs: https://docs.djangoproject.com/en/5.2/ref/databases/#character-fields
MySQL is the most used database: https://db-engines.com/en/ranking