开发者

South django table already exists

开发者 https://www.devze.com 2023-02-09 23:05 出处:网络
I\'m experiencing the same problem as with: django - "manage.py test" fails "table already exists"

I'm experiencing the same problem as with: django - "manage.py test" fails "table already exists"

The schemamigration / migration worked fine (although did have some problems开发者_JAVA百科 that required me to --fake, but all subsequent migrations with south work). But when I run a unit test I get:

(1050, "Table '{tablename}' already exists")

I'm just curious how I can get round this, and why this happens. The only answer given in the question linked above was that south could be excluded from unit tests, if I do this does it mean I can't unit test with tables managed by south?

Explanations much appreciated :)

Adam


No, it doesn't mean that. Don't forget that Django already knows what your tables should look like if you create them from scratch now - it just uses the model definitions. South is useful because it allows you to easily transform your table structure when you change your models, but when you're running tests you don't care about that: you just want the tests run on the current versions of the tables.

So yes, disable South when running tests, via SOUTH_TESTS_MIGRATE = False, and Django will automatically create the tables for you.

0

精彩评论

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