Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
591 views
in Technique[技术] by (71.8m points)

admin - How to fix Django error: " 'unicode' object has no attribute 'tzinfo' " on database read

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' 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This error happens when your database contains date-time stamps like this:

0000-00-00 00:00:00.000000

(this can happen in MySQL if you delete or overwrite a previous date with MySQLWorkbench)

When you try to retrieve these records in a Django model object, you will get an exception from the pytz timezone library:

AttributeError 'unicode' object has no attribute 'tzinfo'

You should edit these dates in your database first, and set them to more recent dates, like 2018-01-01 00:00:00.000000 or set to NULL (but not blank).

See:

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...