从1.7升级到1.8后,我面临着一个Django ValidationError。我搜索了这个错误,但没有运气。
在https://github.com/django/django/blob/master/django%2Fdb%2Fmodels%2Ffields%2F__init__.py#L958
引发错误任何帮助都非常感激。
Django Version: 1.8.3
Exception Type: ValidationError
Exception Value:
[u"'xyz' value must be an integer."]
回溯
Traceback:
File "django/v1_8/core/handlers/base.py" in get_response
116. response = middleware_method(request)
File "/local_middleware.py" in process_request
49. admin = request.user.groups.filter(name='admin')
File "django/v1_8/utils/functional.py" in inner
226. self._setup()
File "django/v1_8/utils/functional.py" in _setup
359. self._wrapped = self._setupfunc()
File "django/v1_8/contrib/auth/middleware.py" in <lambda>
22. request.user = SimpleLazyObject(lambda: get_user(request))
File "django/v1_8/contrib/auth/middleware.py" in get_user
10. request._cached_user = auth.get_user(request)
File "django/v1_8/contrib/auth/__init__.py" in get_user
167. user_id = _get_user_session_key(request)
File "django/v1_8/contrib/auth/__init__.py" in _get_user_session_key
59. return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
File "django/v1_8/db/models/fields/__init__.py" in to_python
969. params={'value': value},
Exception Type: ValidationError at /
Exception Value: [u"'xyz' value must be an integer."]
详述
django/v1_8/db/models/fields/__init__.py in to_python
return value
try:
return int(value)
except (TypeError, ValueError):
raise exceptions.ValidationError(
self.error_messages['invalid'],
code='invalid',
params={'value': value}, ...
)
def validate(self, value, model_instance):
pass
def get_db_prep_value(self, value, connection, prepared=False):
django/v1_8/contrib/auth/middleware.py in <lambda>
def process_request(self, request):
assert hasattr(request, 'session'), (
"The Django authentication middleware requires session middleware "
"to be installed. Edit your MIDDLEWARE_CLASSES setting to insert "
"'django.contrib.sessions.middleware.SessionMiddleware' before "
"'django.contrib.auth.middleware.AuthenticationMiddleware'."
)
request.user = SimpleLazyObject(lambda: get_user(request)) ...
class SessionAuthenticationMiddleware(object):
"""
Formerly, a middleware for invalidating a user's sessions that don't
correspond to the user's current session authentication hash. However, it