wiki:Autodetection

Version 1 (modified by andrew, 6 years ago) (diff)

--

Autodetection

For quite a while, South was manual-only; you had to create migrations by hand. Then, the startmigration command was introduced, which automated the writing of some common migrations - such as adding new models or fields - but you still had to manually say what actions the migration should perform.

Now, as of South 0.5, there is autodetection of most changes to models.py; specifically:

  • Adding and removing models
  • Adding and removing fields from a model
  • Changing a field on a model (only some attributes support changing)
  • Changing the db_table attribute in a model's Meta

Enabling

Autodetection in South is entirely optional, and must be explicitly enabled - autodetection requires that the entire app be frozen into every migration, and so it can lead to clutter.

To use autodetection, you will need to have at least one migration, and you should have created the most recent migration using either --freeze appname (when creating migrations for appname), or have set SOUTH_AUTO_FREEZE_APP = True in your settings.py, which will do this for you automatically.

Usage

Once you have a previous migration with the app state frozen, you can then edit the models.py and make some changes. Once you're ready to make a migration that saves what you've done, run

./manage.py startmigration appname --auto

South will then attempt to determine what's changed, and spit out a new migration for you. It will warn you of anything it knows has changed but which it can't fix (yet).

Bugs

Since this is a new feature, there may be some bugs - we advice you always to check the created file (as you should anyway), and if you do find autodetection to not be working as intended, plaese submit a bug report.