I'm trying out the migrations in Django 1.7 and I was surprised when my 
migrations did not set default values in the database. Can someone share 
the motivation for this functionality? (more details below)

This was surprising given the documentation I read:

   1. the release notes 
   <https://docs.djangoproject.com/en/1.7/topics/migrations/#postgresql> 
   for 1.7 suggest using `null=True` for new database columns, but only 
   because of the potential performance impact during a site update (which 
   seems odd, since the migrations don't set default values anyways…)
   2. the example of a migration 
   <https://docs.djangoproject.com/en/1.7/topics/migrations/#migration-files> 
   file clearly shows a default value of `0` for the Author.rating field, even 
   though it turns out the default isn't used

Running `python manage.py sqlmigrate appname migrationnumber` for an 
example like the Author.rating addition in the docs would look something 
like this:

BEGIN;
ALTER TABLE "author" ADD COLUMN "rating" integer NOT NULL DEFAULT 0;
ALTER TABLE "author" ALTER COLUMN "rating" DROP DEFAULT;

COMMIT;

However, looking in the source code 
<https://github.com/django/django/blob/master/django/db/backends/schema.py#L381>,
 
I can see: "(Django usually does not use in-database defaults)".

I find it quite problematic for production site updates, since my updates 
generally look like:

   1. generate migrations
   2. run migrations on prod db, while old webserver code is still running
   3. after migrations, update webserver

I cannot afford to have breaking problems between steps 2 & 3 if I want to 
add a new db column that is not null and has a default value.

Does anyone here know the motivation for the existing no-defaults-in-the-db 
functionality? I'd like to know, since I'm putting together a backend 
derived from 'django.db.backends.postgresql_psycopg2' that is exactly the 
same, except for setting default values in the db, and I'd like to know 
what concerns there might be for a backend like this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/147340fc-04bc-44c9-aa0a-230635b48d0b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to