[Django] #27859: makemigrations creates migrations that don't work in MySQL

28 views
Skip to first unread message

Django

unread,
Feb 18, 2017, 1:17:13 PM2/18/17
to django-...@googlegroups.com
#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.

Django

unread,
Feb 18, 2017, 6:04:23 PM2/18/17
to django-...@googlegroups.com
#27859: makemigrations creates migrations that don't work in MySQL
-------------------------------+------------------------------------

Reporter: Daniel Quinn | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: MySQL | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Simon Charette):

* 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>

Django

unread,
Feb 19, 2017, 12:54:19 PM2/19/17
to django-...@googlegroups.com
#27859: makemigrations creates migrations that don't work in MySQL
-------------------------------+---------------------------------------
Reporter: Daniel Quinn | Owner: Zubair Alam
Type: Uncategorized | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: MySQL | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by Zubair Alam):

* status: new => assigned
* owner: nobody => Zubair Alam


--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:2>

Django

unread,
Feb 25, 2017, 7:34:10 PM2/25/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL

------------------------------+---------------------------------------
Reporter: Daniel Quinn | Owner: Zubair Alam
Type: Bug | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by Tim Graham):

* keywords: MySQL => mysql
* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:3>

Django

unread,
Feb 26, 2017, 2:45:18 AM2/26/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------+---------------------------------------
Reporter: Daniel Quinn | Owner: Zubair Alam
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by Zubair Alam):

* 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>

Django

unread,
Feb 27, 2017, 8:32:33 AM2/27/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------+---------------------------------------
Reporter: Daniel Quinn | Owner: Zubair Alam
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:5>

Django

unread,
Mar 16, 2017, 8:01:53 AM3/16/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------+---------------------------------------
Reporter: Daniel Quinn | Owner: Zubair Alam
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------

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>

Django

unread,
Apr 15, 2017, 8:34:36 AM4/15/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------+---------------------------------------
Reporter: Daniel Quinn | Owner: Zubair Alam
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by Zubair Alam):

* needs_better_patch: 1 => 0

Django

unread,
Apr 20, 2017, 5:43:20 AM4/20/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------+---------------------------------------
Reporter: Daniel Quinn | Owner: Zubair Alam
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:7>

Django

unread,
May 7, 2017, 1:39:00 PM5/7/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------+------------------------------------
Reporter: Daniel Quinn | Owner: (none)
Type: Bug | Status: new

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Zubair Alam):

* owner: Zubair Alam => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:8>

Django

unread,
May 8, 2017, 1:23:32 AM5/8/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------+------------------------------------
Reporter: Daniel Quinn | Owner: felixxm
Type: Bug | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by felixxm):

* owner: (none) => felixxm


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/27859#comment:9>

Django

unread,
May 8, 2017, 3:04:08 AM5/8/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------------+------------------------------------

Reporter: Daniel Quinn | Owner: felixxm
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql oracle index | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Changes (by felixxm):

* 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>

Django

unread,
May 14, 2017, 12:35:00 PM5/14/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------------+------------------------------------
Reporter: Daniel Quinn | Owner: felixxm
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql oracle index | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

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>

Django

unread,
May 23, 2017, 9:09:59 AM5/23/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------------+------------------------------------
Reporter: Daniel Quinn | Owner: felixxm
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: mysql oracle index | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

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>

Django

unread,
May 23, 2017, 11:02:51 AM5/23/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------------+------------------------------------
Reporter: Daniel Quinn | Owner: felixxm
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: mysql oracle index | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Changes (by GitHub <noreply@…>):

* 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>

Django

unread,
Aug 3, 2017, 2:08:53 PM8/3/17
to django-...@googlegroups.com
#27859: Migration to create TextField with db_index=True crashes on MySQL
------------------------------------+------------------------------------
Reporter: Daniel Quinn | Owner: felixxm
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed
Keywords: mysql oracle index | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages