For MySQL versions prior to 5.0.3, Django will raise a validation error
(when you run "manage.py validate") when you have a CharField with a
max_length > 255. That's been in place for about two years.
There's a problem with external apps when they want to use a field that
large. It means they're basically saying the requirement is a more
recent version of MySQL, which might well be something they're happy
with. Otherwise they have to know about that restriction and change to a
TextField. However Django isn't going to flat-out forbid such fields
just because older versions of one particular database backend have this
restriction. That would unfairly handicap everybody else because of a
problem in MySQL. Thus we make it a validation error only for particular
versions of MySQL.
And, by the way, if you're not running "manage.py validate" every now
and again to check for errors like that, you should start doing so. We
only check that stuff when you run validate to avoid unnecessary
overhead at runtime, since development sanity checking should be done at
development time, not runtime.
Regards,
Malcolm
MySQL it is 255
MSSQL it is 2^31-1 (2gb)
PostgreSQL it is ~ 2^20-1 (1gb)
MySQL 4.1 and greater supposedly changes any varchar or char field
with a max length or greater to 255 to a TEXT field which can hold ~
1gb
Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com
mysql> create table foo ( x varchar(999), primary key (x)) character set
= 'latin1';
Query OK, 0 rows affected (0.00 sec)
mysql> create table foo2 ( x varchar(999), primary key (x)) character
set = 'utf8';
ERROR 1071 (42000): Specified key was too long; max key length is 999 bytes
mysql> create table foo2 ( x varchar(255), primary key (x)) character
set = 'utf8';
Query OK, 0 rows affected (0.01 sec)
So.. if you can live without the benefit of UTF8 you can achieve your
result.
personally I think you should look at your DB-design, as indexes on
large fields are expensive in terms of space used and time to retrieve
results. you could possibly index the MD5 of the field (32 bytes), and
then search for duplicates on that key. it might be faster and cheaper
on the disk.
regards
Ian
Then you should open a ticket, even better if it includes a patch, so
that behaviour similar to that already in
django/db/backends/mysql/validation.py is done for those fields and
those MySQL versions as well.
Again, MySQL-specific validation is quite appropriate here.
>
> As an aside, are most people using Postgres?
Who knows? There's no way of answering a question like that reliably.
Also, raw numbers don't tell the whole story, since the usefulness of a
database backend varies depending on the domain it's being used in.
> Should I switch to that
> for the best tested database for Django?
*shrug* MySQL is a supported backend for Django. Bugs in Django's
support of MySQL should be fixed and if we aren't throwing and error for
the case you describe and if it is a real limitation of MySQL, we should
be doing so, as mentioned above.
Regards,
Malcolm