#27859: makemigrations creates migrations that don't work in MySQL
-----------------------------------------+------------------------
Reporter: Daniel Quinn | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.10
Severity: Normal | Keywords: MySQL
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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
--
Ticket URL: <https://code.djangoproject.com/ticket/27859>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/054.f047949a280e5c931b46131348f91665%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.