如何解决这个错误? " 'unicode'对象没有属性'tzinfo'“ [英] How to fix this error ? " 'unicode' object has no attribute 'tzinfo' "

查看:1647
本文介绍了如何解决这个错误? " 'unicode'对象没有属性'tzinfo'“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows Azure上部署我的Django项目。我使用SQLite作为数据库服务器,一切都OK。当我部署了我的项目时,我决定将它连接到一个SQL Azure数据库,但似乎这个解决方案造成了一些错误。我无法编辑用户个人资料。我总是发现这个错误:
/ 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.

这篇关于如何解决这个错误? &QUOT; 'unicode'对象没有属性'tzinfo'“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆