使用 Nose 运行单元测试时出现 South 错误
我在让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这是否能解决您的问题,但您可以添加一个设置以在运行测试时使用syncdb而不是迁移。将以下行添加到您的 settings.py
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 的文档。
You have a typo in the name of the migration it's depending on. It should be:
This dependency system worked for me, after having exactly the same issue you list here, and then finding the dependency system South's docs.
如果导入目标模块期间出现错误,也会引发此错误:如果您有手动构建的迁移,并且确定文件名与您的 depends_on 或 needed_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.)