﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27859	Migration to create TextField with db_index=True crashes on MySQL	Daniel Quinn	Mariusz Felisiak	"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"	Bug	closed	Migrations	dev	Normal	fixed	mysql oracle index	zubair.alam.jmi@…	Accepted	1	0	0	0	0	0
