This is what I wish to do.

Create a Django project on the development server having a development database. Run the south migrations as necessary after i alter the model.

Save the SQL from each migration, and apply individuals towards the production server when I am prepared to deploy.

Is really a factor possible with South? (I'd be also curious what others do in order to get the development database changes on production whenever using Django)

You can at any rate inspect the sql produced by doing manage.py migrate --db-dry-run --verbosity=2. This can not do anything whatsoever towards the database and can show all of the sql. I'd still create a backup though, better safe than sorry.

I'd either do what Lutger recommended (and perhaps write a log parser to strip out just the SQL), or I'd run my migration against an evaluation database with logging enabled around the test DB.

Obviously, if you're able to run it from the test database, you are only a couple of steps from validating the migration. Whether it passes, run it again against production.

You could attempt logging the SQL queries in db.connection.queries, utilizing a management command that calls the migrate having a dry-run option:


from django.core.management.base import BaseCommand
from django import db

class Command(BaseCommand):
    help = 'Output SQL for migration'

    def handle(self, *app_labels, **options):
        # assumes DEBUG is True in settings
        db.reset_queries()

        from django.core.management import call_command
        kw = {'db-dry-run': 1,  'verbosity': 0}
        call_command('migrate', **kw)

        for query in db.connection.queries:
            print query['sql']

Presuming that south puts everything with the usual db interface that will work. You will see a couple of extra chooses inside if this queries a brief history table.

You'd put that inside a management/commands/print_migration_sql.py within your application after which run it:


python manage.py print_migration_sql

It might most likely easily be extended to operate this just for specific applications etc