使用 Nose 运行单元测试时出现 South 错误

发布于 2024-10-25 18:34:16 字数 691 浏览 6 评论 0原文

我在让 django 测试正常运行时遇到一些困难;我正在使用鼻子,并且在应用迁移时开始出现错误,从表 1 到表 2 的外键关系失败并出现错误:

django.db.utils.DatabaseError: relation "table2_column" does not exist

查看应用迁移的方式,我很清楚table1 不是在应用外键关系之前创建的,所以我试图弄清楚如何强制依赖关系,并找到了以下文章: http://south.aeracode.org/docs/dependency.html

然后我添加:

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

到我的 app1/0001_initial.py 文件。

不幸的是,现在我收到以下错误:

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

有关如何解决此问题的任何想法吗?

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: relation "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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

四叶草在未来唯美盛开 2024-11-01 18:34:16

我不确定这是否能解决您的问题,但您可以添加一个设置以在运行测试时使用syncdb而不是迁移。将以下行添加到您的 settings.py

SOUTH_TESTS_MIGRATE = False

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
无人问我粥可暖 2024-11-01 18:34:16

您所依赖的迁移名称有拼写错误。它应该是:

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

这个依赖系统对我有用,在遇到与您在此处列出的完全相同的问题之后,然后找到依赖系统 South 的文档。

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.

太阳哥哥 2024-11-01 18:34:16

如果导入目标模块期间出现错误,也会引发此错误:如果您有手动构建的迁移,并且确定文件名与您的 depends_onneeded_by 匹配,检查引用的文件是否有错误。

此外,将 SOUTH_TESTS_MIGRATE 设置为 False 并不能解决问题。这只是意味着您在尝试使用迁移之前不会看到问题。

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

(如果您想加快单元测试速度,这仍然很有用。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文