2

I know there are many posts about this error. Such as: this and this one

But I knew already that. And that's why I'm getting crazy.

When I create an instance and try to save it, I don't have problems:

per_detail.preview_title = per_detail.details_sample.preview_title
per_detail.icon = per_detail.details_sample.icon
per_detail.content = fill_content(per_detail)
per_detail.save()

easy.

But when there's already the instance, and I try to save it again (updated it). Then I get this error:

match = datetime_re.match(value)

TypeError: expected string or bytes-like object

whit this code:

personal_detail_sample = kwargs['instance']
        personal_details = PersonalDetail.objects.filter(Q(details_sample=personal_detail_sample))
        for per_detail in personal_details:
            per_detail_updated = fill_updated_content(personal_detail_sample, per_detail)
            per_detail_updated.save()

I gotta say, it doesn't matter where I try to update that instance, I get always the same error. (so, it's not because the kwargs['instance'])

And here's the field, that is giving troubles:

sent_date = models.DateTimeField(_('sent_date'), null=True, blank=True)

As you maybe noticed, I never filled the field "sent_date", but it should be null. So it shouldn't be a problem. And for just being safe, I also tried to do:

per_detail.sent_date = *a date*
per_detail.save()

And I'm getting the same error.

I don't have any idea what could it be.

Maybe someone can help me.

5
  • value is not a string or bytes-like object (maybe it's Unicode, maybe it's a Django field type - didn't read you question in enough detail), in any case you should probably print its value/type/repr - or set a breakpoint and inspect it... Commented Mar 24, 2017 at 20:27
  • remove auto_now_add and try again Commented Mar 24, 2017 at 20:32
  • No chance... I removed the auto_now_add and I debugged and I got sent_date = None which for a database would be "null" and I permit it. I made "makemigrations" and "migrate" several times, just in case, and same result. :( I don't have any idea... Commented Mar 24, 2017 at 20:36
  • I also did per_detail_updated.sent_date = datetime.datetime.now() with sent_date = 2017-03-24 20:37:48.584796 (debugged) and got the same error. I'm thinking about erasing every migrations and makemigrations again... Commented Mar 24, 2017 at 20:39
  • Erasing the migrations and making it again resolved nothing. Commented Mar 24, 2017 at 20:41

1 Answer 1

1

I got an error in the field "date" not "sent_date".

I'm pretty sorry. The field of "date" in the models.py was:

date = models.DateTimeField(_('date'), auto_now_add=True) but in the DataBase was time without time zone and not timestamp without time zone. Why? Who knows...

I deleted the sent_date field, and saw, that there was another error with a date, and that's why I found the error.

Many thanks to the people that tried to help!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.