我被要求为内部 MSSQL 数据库创建一个简单的 Web 前端。我正在使用 django-pyodbc-azure 。
我终于配置并运行了所有东西,但是现在当我尝试登录管理页面时,我得到一个“unicode”对象没有属性“tzinfo”错误。我在这里尝试了这个建议,但似乎没有帮助。非常欢迎任何建议!
解决方案由 miyamoto 发布。我必须在 Django中将“use_legacy_datetime”:True添加到我的数据库连接选项中,然后我必须手动将数据库中的所有 Datetime2 列更改为 Datetime。
可以在此处找到有关该解决方案的更多信息。
这是堆栈跟踪以供将来参考:
Environment:
Request Method: POST
Request URL: http://****:7777/admin/login/?next=/admin/
Django Version: 1.9.7
Python Version: 2.7.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in login
414. return login(request, **defaults)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/contrib/auth/views.py" in inner
49. return func(*args, **kwargs)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/contrib/auth/views.py" in login
76. auth_login(request, form.get_user())
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in login
110. request.session.cycle_key()
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in cycle_key
307. self.delete(key)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in delete
98. self.model.objects.get(session_key=session_key).delete()
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
122. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in get
381. num = len(clone)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
240. self._fetch_all()
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
1074. self._result_cache = list(self.iterator())
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in __iter__
68. for row in compiler.results_iter(results):
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
808. row = self.apply_converters(row, converters)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in apply_converters
792. value = converter(value, expression, self.connection, self.query.context)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/sql_server/pyodbc/operations.py" in convert_datetimefield_value
106. value = timezone.make_aware(value, timezone.utc)
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/utils/timezone.py" in make_aware
367. if is_aware(value):
File "/sites/flashlog/venv/local/lib/python2.7/site-packages/django/utils/timezone.py" in is_aware
340. return value.utcoffset() is not None
Exception Type: AttributeError at /admin/login/
Exception Value: 'unicode' object has no attribute 'utcoffset'