Do I need to call syncdb before or after South migrate
Asked Answered
P

2

10

I'm new to South so I am wondering if I ever need to call

./manage.py syncdb

or doing

./manage.py schemamigration appname --auto
./manage.py migrate appname

is sufficient in all cases South can handle on its own.

Pittance answered 13/6, 2011 at 21:20 Comment(1)
I had this exact same question after reading the south docs. They are good but a clearer explanation of this relationship would definitely not be out of place.Ailing
A
21

South isn't project wide. It is app wide.
Some apps use south, some apps don't use it.

if an app is integrated south, to do db changes you will use

./manage.py schemamigration appname --auto
./manage.py migrate appname

but not all apps are integrated with south.

When you add a new app that don't use south to your project, you need to call ./manage.py syncdb for these apps. (For example, django.contrib apps)

In short, use ./manage.py syncdb when an app doesn't use south, and ./manage.py migrate for south integrated apps.

Anatolia answered 13/6, 2011 at 23:13 Comment(4)
Thank you for a clear explanation. I edited your answer to add some formatting.Pittance
I found South behavior confusing until I realized that South changes syncdb behavior. One installed, syncdb is a no-op on apps managed by South. So you can run syncdb on a site even if it has some apps managed by south. You have to be careful when you first install south that the syncdb and initial migrations are consistent, but once you've done that, it's nicely error-tolerant.Claribel
Something to be aware of is that South migrations are run before any fixture for the app is loaded. I've just come across this, because I was trying to run a data migration that was assuming that rows in the initial_data.json fixture had already been loaded.Midis
Note: If you're converting an existing app (one that had already been managed by ./manage.py syncdb) check out south.readthedocs.org/en/latest/…Alexisaley
A
8

When you create or install a new app MyApp, you should first execute the following commands:

./manage.py schemamigration MyApp --inital
./manage.py migrate MyApp

After that whenever you execute ./manage.py syncdb you will see:

Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

Synced:
 > south
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.messages
 > django.contrib.staticfiles
 > django.contrib.admin
 > django.contrib.admindocs

Not synced (use migrations):
 - MyApp
(use ./manage.py migrate to migrate these)

You can see that manage.py syncdb is able to differentiate between apps managed by South (Not synced section) and those not managed by South (Synced section). It also reminds you to use ./manage.py migrate.

The important point is to let South manage a new app by executing ./manage.py schemamigration MyApp --inital and ./manage.py migrate MyApp before executing ./manage.py syncdb.

Alesha answered 17/6, 2013 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.