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

  • SEARCH
  • Home
  • 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 8351059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:31:06+00:00 2026-06-09T08:31:06+00:00

If have the following Django (1.4) model: from django.db import models class SimpleModel(models.Model): name

  • 0

If have the following Django (1.4) model:

from django.db import models

class SimpleModel(models.Model):
    name = models.CharField(max_length=100)

And this simple test:

from django.test import TestCase
from models import SimpleModel
from django.db import IntegrityError

class SimpleTest(TestCase):
    def test_integrity_error(self):
        with self.assertRaises(IntegrityError):
            m = SimpleModel()
            m.save()

As database a sqlite3 database is used. If I now run the tests with python manage.py test <appname> the test fails with AssertionError: IntegrityError not raised.

The question is: why?

As far as I understand (or thought to understand) Django the default values for Fields are blank=False and null=False so I would assume that saving an model instance with the default value (which I think for a CharField should be an empty string) should certainly fail! So, why doesn’t this happen?

  • 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-06-09T08:31:07+00:00Added an answer on June 9, 2026 at 8:31 am

    Django never stores NULL for empty CharField or TextField types. It stores an empty string (''). So that’s why you don’t get an IntegrityError for null=False.

    As for blank=False, that only affects forms. It just makes the form set the field as required=True so it won’t validate unless it has a value. It doesn’t affect the database or your ability to manually set a blank value outside of a form.

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

Sidebar

Related Questions

I have the following model: from django.db import models class State(models.Model): name = models.CharField(max_length=30)
I have the following abstract Django models: class Food(models.Model): name = models.CharField(max_length=100) class Meta:
I have the following model. from django.db import models class Client(models.Model): postcode = models.CharField(max_length=10)
Let's assume we have following models: from django.db import models class Foo(models.Model): name =
Suppose I have the following Event model: from django.db import models import datetime class
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have the following model: from django.db import models import datetime class Club(models.Model): establishment
I have the following: from django.contrib.auth.models import User class ClientDetails(models.Model): created_by = models.ForeignKey(User) ...
I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #
I have the following model in Django: from django.db import models class User(models.Model): pen_name

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.