如何解决这个错误? " 'unicode'对象没有属性'tzinfo'“ [英] How to fix this error ? " 'unicode' object has no attribute 'tzinfo' "
问题描述
/ admin / auth / user / 1 /
'unicode'对象的AttributeError没有属性'tzinfo'
我曾尝试使用Django(1.5.1)使用 django-pyodbc-azure
数据库后端的问题:默认情况下,它存储 DateTimeField
您的数据库中的字段为 datetime2(7)
,这在Django中仍然不受支持。
在我的情况下,我在 settings.py
中添加了选项'use_legacy_datetime':True
,如下所示:
DATABASES = {
'default':{
'ENGINE':'sql_server.pyodbc'
'NAME':'< MYDBNAME>',
'USER':'< MYDBUSER>',
'PASSWORD':'< MYDBPWD>',
' HOST':'< MYHOST>',
'OPTIONS':{
'use_mars':True,
'use_legacy_datetime':True,#我添加了这行
}
},
}
我发现我的解决方案 here 。
我不太了解Azure平台,所以我不知道这是否完全符合您的情况,如果不能,您仍然可以修改您的数据库替换 datetime2(N)
字段与旧的 datetime
一个。
希望它有帮助。
I am deploying my Django project on Windows Azure. I was using SQLite as a database server and everything was ok. When I have deployed My project, I decided to connect it with an SQL Azure Database but it seems that this solution created some errors. I am no longer able to edit users profiles. I get always this error : AttributeError at /admin/auth/user/1/ 'unicode' object has no attribute 'tzinfo'
I had same issue trying to use django-pyodbc-azure
database backend with Django (1.5.1): by default it stores DateTimeField
fields in your DB as datetime2(7)
, which looks to be still unsupported in Django.
In my case I added the option 'use_legacy_datetime' : True
in settings.py
, like below:
DATABASES = {
'default': {
'ENGINE' : 'sql_server.pyodbc',
'NAME' : '<MYDBNAME>',
'USER': '<MYDBUSER>',
'PASSWORD': '<MYDBPWD>',
'HOST': '<MYHOST>',
'OPTIONS': {
'use_mars': True,
'use_legacy_datetime' : True, # I added this line
},
},
}
I found my solution here.
I don't know Azure platform well, so I don't know if this is exactly your case, if not you can still modify your database replacing datetime2(N)
fields with good old datetime
ones.
Hope it helps.
这篇关于如何解决这个错误? " 'unicode'对象没有属性'tzinfo'“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!