[Solved]-Django ORM, CharField and blank=True

7πŸ‘

βœ…

As is usually the case with problems that are so seemingly intractable, the issue at hand was user error.

My application had two entry points – two WSGI files, but only one code base. Normally, Apache will only reload your code if the file is touched. My deploy script was only touching one of those WSGI files – which meant that people reaching my site via the other WSGI file were still seeing old code. Worse, the database was modified under that old code, but the models were still as they were before.

This in turn caused the IntegrityError issues. Django didn’t know about the phone_number field, so even though I had set blank=True, Django made no effort to insert a blank value – and the database of course thought that meant NULL.

This caused a series of different to track down errors, including the above error.

It’s amazing how often really tough issues like these are caused by dumb minor omissions – like a deploy script I wrote 2 months ago and forgot to update.

Thanks for reading folks, I’ve upvoted the other answers, but I need to accept mine since it was ultimately the solution.

πŸ‘€philipk

6πŸ‘

I discovered that if you explicitly set the field value to None you will still get these errors. In other words the default= thing is applied as soon as you create the python object, rather then when you save it to the database.

I guess that is reasonable but it was a bit unexpected.

πŸ‘€Timmmm

Leave a comment