Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6348069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:20:53+00:00 2026-05-24T21:20:53+00:00

Django’s documentation is quite clear about storing empty strings as rather than NULL at

  • 0

Django’s documentation is quite clear about storing empty strings as “” rather than NULL at a database level (so there is only one possible format for empty data):

Note that empty string values will always get stored as empty strings, not as NULL. Only use null=True for non-string fields such as integers, booleans and dates. For both types of fields, you will also need to set blank=True if you wish to permit empty values in forms, as the null parameter only affects database storage (see blank).

Nonetheless, after adding a new field, I’ve started encountering IntegrityErrors on the new field (phone_number).

null value in column “phone_number” violates non-null constraint

That model looks like this with the new field (I performed a migration via south):

class Person(models.Model):
    user = models.ForeignKey(User)
    description = models.TextField(blank=True)
    phone_number = models.CharField(blank=True)

I’ve since (temporarily) resolved the issue by setting null=True on phone_number, but now I have hundreds of entries with empty strings, and a single NULL value in my database. (I also tried adding default=” to the phone_number field, but I was still seeing IntegrityError issues.)

In the past I’ve always used MySQL, but on this project I’m using Postgres. The generated SQL insert attempt is:

'INSERT INTO "people_person" ("user_id", "description", "gender", "birthdate", "default_image_id", "zip_code", "beta_status") VALUES (%s, %s, %s, %s, %s, %s, %s) RETURNING "people_person"."id"'.

My expectation would be that Django would be inserting a blank string into the “phone_number” column, but it doesn’t appear to be doing so. The other thing I might expect would be Django to include a SET DEFAULT in the CREATE TABLE statement, but it doesn’t. So Postgres gets angry about the NOT NULL on that column.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:20:54+00:00Added an answer on May 24, 2026 at 9:20 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Django (1.2 beta) will reset the database(s) between every test that runs, meaning each
Django's views documentation states that the default 500 view passes no variables to this
Django as a framework is a neat little package. There are very few files
Django models generally handle the ON DELETE CASCADE behaviour quite adequately (in a way
Django can make use of multiple database engines at the same time. My problem
django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database geodatabase. GeoDjango requires at least PostGIS version
Django has the StackedInline-Feature for the Admin-Backend - is there any equivalent for django.forms?
Django only allows you to use one database in settings.py. Does that prevent you
django nonrel's documentation states: you have to manually write code for merging the results
In Django how do you remove models that you have synced into the database?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.