Django 1.3 and southern migrations

I have an existing project that actively uses southern migrations to load data into its tables.

Since upgrading to Django 1.3, our unit tests no longer run because they cannot find the data they rely on.

+6
source share
2 answers
  • Yes, this behavior is related to this change.

    There seems to be a workaround in the South trunk (see https://bitbucket.org/andrewgodwin/south/changeset/21a635231327 ) so you can try the development version in the South (it is pretty stable in my experience).

  • You can try changing the database name in the settings (to get a clean environment), run ./manage.py syncdb and ./manage.py migrate , and then do ./manage.py dumpdata

+3
source

Today I got into this problem. In the end, I ended up refactoring my migrations so that they use helper functions to actually insert the data, and then call the same functions from setUp () of my tests.

Some clues;

  • Make your helper functions a model class as an argument, so you can call them using orm ['yourapp.YourModel'] from the migration and using models. Your model from the test. This also shows a major limitation: South works for models whose layout has changed since then, test code cannot do this. I am fortunate that this particular model has not changed.

  • If you want to keep helper methods inside migrations, you will find that you cannot directly import yourapp.migrations.0001_some_migration, since identifiers cannot begin with numbers. Instead of the import statement, use migration_0001 = importlib.import_module('yourapp.migrations.0001_some_migration') .

0
source

Source: https://habr.com/ru/post/892043/


All Articles