Opened 9 years ago

Closed 7 years ago

Last modified 3 years ago

#2231 closed defect (invalid)

Boolean fields don't honor 'default' parameter

Reported by: russellm Owned by: russellm
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 Changed 9 years ago by russellm

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 9 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

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

comment:3 Changed 7 years ago by guettli

  • Cc hv@… added
  • Resolution invalid deleted
  • Status changed from closed to reopened

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 Changed 7 years ago by russellm

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

comment:5 Changed 7 years ago by russellm

  • Resolution set to invalid
  • Status changed from reopened to closed

comment:6 Changed 3 years ago by guettli

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