Opened 12 years ago

Closed 10 years ago

Last modified 6 years ago

#2231 closed defect (invalid)

Boolean fields don't honor 'default' parameter

Reported by: Russell Keith-Magee Owned by: Russell Keith-Magee
Component: Database layer (models, ORM) Version:
Severity: normal Keywords: boolean default
Cc: martinson.jacob@…, freakboy3742@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Jacob Martinson <martinson.jacob@…> reports that in the model:

class Response(models.Model):
      responded = models.BooleanField(default=False)

The postgresql table that gets created does not have a default value
for the "responded" column and I get a sql exception if I don't
manually set responded to 'f' when I save each new Response object.

Change History (6)

comment:1 Changed 12 years ago by Russell Keith-Magee

Further investigation reveals that this might not actually be a problem - Follow the user mailing list thread ("Default value for boolean field") for more details.

comment:2 Changed 12 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

Looks to be completely unrepeatable now (even by Jacob). Please reopen if it appears again.

comment:3 Changed 10 years ago by Thomas Güttler

Cc: hv@… added
Resolution: invalid
Status: closedreopened

It is repeatable:

Current trunk

cd django/trunk; svn update
Aktualisiert zu Revision 9391.
django-admin startapp booltest

# booltest/
from django.db import models
class TestModel(models.Model):
> sqlall booltest

CREATE TABLE "booltest_testmodel" (
    "id" serial NOT NULL PRIMARY KEY,
    "truth" boolean NOT NULL

DATABASE_ENGINE = 'postgresql_psycopg2'

I expected:

  "truth" boolean NOT NULL DEFAULT FALSE

comment:4 Changed 10 years ago by Russell Keith-Magee

Default isn't handled at the SQL level - it's handled at the model level.

comment:5 Changed 10 years ago by Russell Keith-Magee

Resolution: invalid
Status: reopenedclosed

comment:6 Changed 6 years ago by Thomas Güttler

Cc: hv@… removed
Easy pickings: unset
UI/UX: unset
Note: See TracTickets for help on using tickets.
Back to Top