Opened 13 years ago
Closed 13 years ago
#16077 closed Bug (invalid)
syncdb, PostgreSQL: models.IntegerField default value is absent in the created SQL
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If some model has an IntegerField with option "default" set, then "./manage.py syncdb" will create PostgreSQL table with integer field without "DEFAULT" SQL keyword. So that is impossible to set default value for this model attribute.
Example:
model:
class AmProfile(models.Model):
my_field = models.IntegerField(default=1)
produced SQL:
my_field integer NOT NULL,
but should be:
my_field integer DEFAULT 1 NOT NULL,
Note:
See TracTickets
for help on using tickets.
The default value can be a value or a callable, so it's not possible to include it in the generated SQL.
However, it will still be used whenever you create a new instance of your model.
See https://docs.djangoproject.com/en/1.3/ref/models/fields/#default