#27859 closed Bug (fixed)
Migration to create TextField with db_index=True crashes on MySQL
Reported by: | Daniel Quinn | Owned by: | Mariusz Felisiak |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | mysql oracle index |
Cc: | zubair.alam.jmi@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a GPL project that uses Django as its base that typically works using SQLite. However, some of my users have been trying to use it with MySQL and this has presented a strange annoyance.
In one of my models, I have this line:
content = models.TextField(db_index=True)
this generates a migration that looks like this:
... ('content', models.TextField(db_index=True)), ...
...which seems reasonable enough to me. However, while this works just fine in SQLite and PostgreSQL, users attempting to install the project using MySQL were treated to this explosion when they ran manage.py migrate
:
django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'content' used in key specification without a key length")
Now understandably, if you're writing a project *for* MySQL, you wouldn't put an index on a TextField because you know that MySQL doesn't support that, but in the interests of portability, I would think a warning, coupled with ignoring the index specification would be more appropriate.
For now, I've just had to rewrite the migration to look like this:
('content', models.TextField(db_index=("mysql" not in settings.DATABASES["default"]["ENGINE"]))),
I'm not proud of that one, but it works for now :-)
There's a longer discussion about this issue on my project's GitHub issue page here: https://github.com/danielquinn/paperless/issues/183 if you're interested.
https://github.com/danielquinn/paperless/issues/183#issuecomment-280863310
Change History (14)
comment:1 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.10 → master |
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
Keywords: | mysql added; MySQL removed |
---|---|
Summary: | makemigrations creates migrations that don't work in MySQL → Migration to create TextField with db_index=True crashes on MySQL |
Type: | Uncategorized → Bug |
comment:4 by , 8 years ago
Cc: | added |
---|---|
Has patch: | set |
Please find the patch at pull request https://github.com/django/django/pull/8118
comment:5 by , 8 years ago
Patch needs improvement: | set |
---|
comment:6 by , 8 years ago
Patch needs improvement: | unset |
---|
comment:7 by , 8 years ago
Patch needs improvement: | set |
---|
comment:8 by , 8 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:9 by , 8 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:14 by , 7 years ago
I have a PR that partially reverts this fix and allows for TextField.db_index
for MySQL. Thoughts?
Related to #2495.
I also think the correct way of handling that would be to make MySQL's schema editor ignores
db_index
onTextField
.