Hello, I wrote a script to convert from an old database (turbogears) to django. It involved a few loops like this:
for oldm in messages: newm = models.Message() newm.date = oldm.date newm.text = oldm.text newm.save() After running the script, I discovered that all the messages in the new DB had the same date. This was very strange, because everything else was ok. This was even more strange, because this worked fine: >>> m = models.Message.objects.get(id=1) >>> m.date = datetime(2007, 4, 4) >>> m.save() It took me a very long and unpleasant hour to discover that it was because the date field had auto_now_add=True. I fixed my script, so now the loop looks like this: for oldm in messages: newm = models.Message() newm.text = oldm.text newm.save() newm.date = oldm.date newm.save() The conclusion is that auto_now_add should set the date only if it is None. Or, another solution: it should set the date upon instance creation, not upon saving. Do you agree? Noam --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---