Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 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 Answer

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...