Opened 18 years ago

Closed 15 years ago

Last modified 12 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

Description

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 by Russell Keith-Magee, 18 years ago

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 by Malcolm Tredinnick, 18 years ago

Resolution: invalid
Status: newclosed

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

comment:3 by Thomas Güttler, 15 years ago

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/models.py
from django.db import models
class TestModel(models.Model):
    truth=models.BooleanField(default=False)
>django-admin.py sqlall booltest

BEGIN;
CREATE TABLE "booltest_testmodel" (
    "id" serial NOT NULL PRIMARY KEY,
    "truth" boolean NOT NULL
)
;
COMMIT;

DATABASE_ENGINE = 'postgresql_psycopg2'

I expected:

  ...
  "truth" boolean NOT NULL DEFAULT FALSE

comment:4 by Russell Keith-Magee, 15 years ago

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

comment:5 by Russell Keith-Magee, 15 years ago

Resolution: invalid
Status: reopenedclosed

comment:6 by Thomas Güttler, 12 years ago

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