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.
* version: 1.10 => master
* stage: Unreviewed => Accepted
Comment:
Related to #2495.
I also think the correct way of handling that would be to make MySQL's
schema editor ignores `db_index` on `TextField`.
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:1>
* status: new => assigned
* owner: nobody => Zubair Alam
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:2>
* keywords: MySQL => mysql
* type: Uncategorized => Bug
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:3>
* cc: zubair.alam.jmi@… (added)
* has_patch: 0 => 1
Comment:
Please find the patch at pull request
`https://github.com/django/django/pull/8118`
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:4>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:5>
Comment (by Zubair Alam):
Have made changes in pull request
[https://github.com/django/django/pull/8118]
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:6>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:7>
* owner: Zubair Alam => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:8>
* owner: (none) => felixxm
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:9>
* keywords: mysql => mysql oracle index
* needs_better_patch: 1 => 0
Comment:
[https://github.com/django/django/pull/8471 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:10>
Comment (by GitHub <noreply@…>):
In [changeset:"5cff2cb4c09363ee871d1993e3acbad6fb96c05b" 5cff2cb4]:
{{{
#!CommitTicketReference repository=""
revision="5cff2cb4c09363ee871d1993e3acbad6fb96c05b"
Refs #27859 -- Refactored BaseDatabaseValidation to use
check_field_type().
Thanks Tim Graham for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:11>
Comment (by Tim Graham <timograham@…>):
In [changeset:"b3eb6eaf1a197ff155faf333871da032c77ba855" b3eb6eaf]:
{{{
#!CommitTicketReference repository=""
revision="b3eb6eaf1a197ff155faf333871da032c77ba855"
Refs #27859 -- Added DatabaseWrapper.display_name.
Thanks Tim Graham for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:12>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"538bf43458a147b7edeb7118c9f325c3f59ff6fb" 538bf434]:
{{{
#!CommitTicketReference repository=""
revision="538bf43458a147b7edeb7118c9f325c3f59ff6fb"
Fixed #27859 -- Ignored db_index for TextField/BinaryField on Oracle and
MySQL.
Thanks Zubair Alam for the initial patch and Tim Graham for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:13>
Comment (by Claude Paroz):
I have a [https://github.com/django/django/pull/8848 PR] that partially
reverts this fix and allows for `TextField.db_index` for MySQL. Thoughts?
--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:14>