Error message regarding mysql version is never used in the code added by r9650
|Reported by:||ElliottM||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.0|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In django.db.backends.mysql.validation, there is the following code to handle validation of varchar fields:
19 if db_version < (5, 0, 3): 20 msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %(version)s).' 21 if f.unique == True: 22 msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".' 23 else: 24 msg = None
If you look carefully, the mysql version ends up being irrelevant. The cause is the "else" on line 23. The "if" it matches to only tests for unique=True, so if unique is false then msg will be None, even if the user has an incompatible mysql version.
To solve it, I removed the else, put "msg=None" above the two if ststements, then switched the two if statements. The reason for the switch is that if the user both has a unique field and has an incompatible version, we want to display the incompatible version error message.