Search code examples
pythondjangodjango-south

django south migration, doesnt set default


I use south to migrate my django models. There is however a nasty bug in south. It doesn't set default values in Postgres Databases. Example:

created_at = models.DateTimeField(default = datetime.now)
tag_id = models.PositiveIntegerField(default = 0)

South will add these 2 fields to database, but fail to set their default values, which needs to be done manually.

Is there any patch for this bug?

UPDATE I had already tried setting default date with auto_now_add=True, but that is also not setting defaults. Adding null=True in field adds a db.alter_column in migration script produced by south. But that only removes NOT NULL constraint, doesnt add a default. Same for integer field


Solution

  • This is not a bug, in South or elsewhere.

    I think you are confused about how default values work in Django generally. Django does not set default values in the database schema. It applies them directly in Python, when a new instance is created. You can verify this by doing manage.py sqlall and see that the generated SQL does not contain default attributes.