I have following Django model code:
status = models.PositiveIntegerField(default = 0b000)
comments_allowed = models.BooleanField(default = True)
The only permanent solution is to patch the Django source, specifically db/backends/creation.py:
Find:
if f.primary_key:
field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
elif f.unique:
field_output.append(style.SQL_KEYWORD('UNIQUE'))
After add:
if(f.default != models.fields.NOT_PROVIDED):
field_output.append(style.SQL_KEYWORD('DEFAULT ' + str(f.default)))
(Source: http://www.supermind.org/blog/671/django-not-setting-default-column-value-in-mysql)
Alternatively (and preferably), if you're using South, you can just execute some additional SQL after the db.create_table in your migration:
MySQL:
db.execute("ALTER TABLE yourapp_yourmodel MODIFY status int Default '4'")
Postgres:
db.execute("ALTER TABLE yourapp_yourmodel ALTER COLUMN status SET DEFAULT 4")