Opened 9 years ago

Closed 9 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: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

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@…> 9 years ago.

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by Michal Ludvig <michal@…>

Attachment: db-default.diff added

comment:1 Changed 9 years ago by Gary Wilson <gary.wilson@…>

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 Changed 9 years ago by Malcolm Tredinnick

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