开发者

Error With South When Running Unit Tests Using Nose

开发者 https://www.devze.com 2023-02-18 22:43 出处:网络
I\'m having some difficulty getting my django tests to run properly; I\'m using nose, and I started getting an error when the migrations were being applied, that from table 1 a foreign key relation to

I'm having some difficulty getting my django tests to run properly; I'm using nose, and I started getting an error when the migrations were being applied, that from table 1 a foreign key relation to table 2 failed with the error:

django.db.utils.DatabaseError: r开发者_运维知识库elation "table2_column" does not exist

Looking at the way the migrations were being applied it was clear to me that table1 was not created prior to the foreign key relation was applied, so I tried to figure out how to force the dependency, and found the following article: http://south.aeracode.org/docs/dependencies.html

I then added:

depends_on = (
    ("app2", "0001_inital"),
)

to my app1/0001_initial.py file.

Unfortunately now I'm getting the following error:

south.exceptions.DependsOnUnknownMigrationMigration 'app1:0001_initial' depends on unknown migration 'app2:0001_inital'.

Any ideas on how to solve this?


I'm not sure if this will solve your problem, but you can add a setting to use syncdb instead of migrations when running tests. Add the following line to your settings.py

SOUTH_TESTS_MIGRATE = False


You have a typo in the name of the migration it's depending on. It should be:

depends_on = (
    ("app2", "0001_initial"),
)

This dependency system worked for me, after having exactly the same issue you list here, and then finding the dependency system South's docs.


This error is also thrown if there is an error during the import of the target module: If you've got hand-constructed migrations and you're certain the file name matches your depends_on or needed_by, check the referenced file for errors.

Also, setting SOUTH_TESTS_MIGRATE to False won't fix the problem. It just means you won't see the problem until you try to use the migration.

http://south.readthedocs.org/en/latest/settings.html

(That's still useful if you want to speed up your unittests.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号