Opened 17 years ago

Closed 17 years ago

#4800 closed (duplicate)

Field's default value in model isn't passed to SQL

Reported by: Michal Ludvig <michal@…> Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I have a model roughly like this:

class Foo(models.Model):
    blah = models.BooleanField(default=True)

I expect "syncdb" to create SQL field with the default value set (this is for mysql):

`blah` tinyint(1) NOT NULL DEFAULT '1',

Unfortunately it doesn't, the "DEFAULT '1'" part is missing. Apparently there is no checking for 'field.default' value in django/core/management.py:_get_sql_model_create()

Attached patch adds this functionality.

Attachments (1)

db-default.diff (984 bytes ) - added by Michal Ludvig <michal@…> 17 years ago.

Download all attachments as: .zip

Change History (3)

by Michal Ludvig <michal@…>, 17 years ago

Attachment: db-default.diff added

comment:1 by Gary Wilson <gary.wilson@…>, 17 years ago

Patch needs improvement: set
Triage Stage: UnreviewedDesign decision needed

A couple things:

  • If we are going to add this, it needs to be for more than just BooleanField.
  • Since default values can be given callables, the default value might not be determined until runtime. You would not want the default value specified at the database level in this case.

comment:2 by Malcolm Tredinnick, 17 years ago

Resolution: duplicate
Status: newclosed

Dupe of #470 (which has been wontfixed twice so far).

Note: See TracTickets for help on using tickets.
Back to Top