mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #2188 -- Raise an error when using long CharFields in combination with
older MySQL versions. Thanks, Fraser Nevett <mail@nevett.org> . git-svn-id: http://code.djangoproject.com/svn/django/trunk@3855 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5371ee1743
commit
4e76727fec
1
AUTHORS
1
AUTHORS
@ -119,6 +119,7 @@ answer newbie questions, and generally made Django that much better:
|
||||
Eric Moritz <http://eric.themoritzfamily.com/>
|
||||
Robin Munn <http://www.geekforgod.com/>
|
||||
Nebojša Dorđević
|
||||
Fraser Nevett <mail@nevett.org>
|
||||
Sam Newman <http://www.magpiebrain.com/>
|
||||
Neal Norwitz <nnorwitz@google.com>
|
||||
oggie rob <oz.robharvey@gmail.com>
|
||||
|
@ -820,7 +820,8 @@ def get_validation_errors(outfile, app=None):
|
||||
validates all models of all installed apps. Writes errors, if any, to outfile.
|
||||
Returns number of errors.
|
||||
"""
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.db import models, connection
|
||||
from django.db.models.loading import get_app_errors
|
||||
from django.db.models.fields.related import RelatedObject
|
||||
|
||||
@ -862,6 +863,12 @@ def get_validation_errors(outfile, app=None):
|
||||
if f.db_index not in (None, True, False):
|
||||
e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name)
|
||||
|
||||
# Check that maxlength <= 255 if using older MySQL versions.
|
||||
if settings.DATABASE_ENGINE == 'mysql':
|
||||
db_version = connection.get_server_version()
|
||||
if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.maxlength > 255:
|
||||
e.add(opts, '"%s": %s cannot have a "maxlength" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join(str(n) for n in db_version[:3])))
|
||||
|
||||
# Check to see if the related field will clash with any
|
||||
# existing fields, m2m fields, m2m related objects or related objects
|
||||
if f.rel:
|
||||
|
@ -13,6 +13,7 @@ except ImportError, e:
|
||||
from MySQLdb.converters import conversions
|
||||
from MySQLdb.constants import FIELD_TYPE
|
||||
import types
|
||||
import re
|
||||
|
||||
DatabaseError = Database.DatabaseError
|
||||
|
||||
@ -24,6 +25,8 @@ django_conversions.update({
|
||||
FIELD_TYPE.TIME: util.typecast_time,
|
||||
})
|
||||
|
||||
server_version_re = re.compile('[.-]')
|
||||
|
||||
# This is an extra debug layer over MySQL queries, to display warnings.
|
||||
# It's only used when DEBUG=True.
|
||||
class MysqlDebugWrapper:
|
||||
@ -61,6 +64,7 @@ class DatabaseWrapper(local):
|
||||
def __init__(self):
|
||||
self.connection = None
|
||||
self.queries = []
|
||||
self.server_version = None
|
||||
|
||||
def _valid_connection(self):
|
||||
if self.connection is not None:
|
||||
@ -110,6 +114,14 @@ class DatabaseWrapper(local):
|
||||
self.connection.close()
|
||||
self.connection = None
|
||||
|
||||
def get_server_version(self):
|
||||
if not self.server_version:
|
||||
if not self._valid_connection():
|
||||
self.cursor()
|
||||
version = server_version_re.split(self.connection.get_server_info())
|
||||
self.server_version = tuple([int(x) for x in version[:3]]) + tuple(version[3:])
|
||||
return self.server_version
|
||||
|
||||
supports_constraints = True
|
||||
|
||||
def quote_name(name):
|
||||
|
Loading…
Reference in New Issue
Block a user