测试时无法安装auth.group fixture - django 1.7

时间:2022-09-20 13:45:34

I have a django project and I am trying to write some tests for it. However, my initial_data fixtures cause an error when running the test.

我有一个django项目,我正在尝试为它编写一些测试。但是,我的initial_data fixtures在运行测试时会导致错误。

The error that I am getting is:

我得到的错误是:

django.db.utils.ProgrammingError: Problem installing fixture 'accounts/fixtures/initial_data.json': Could not load auth.Group(pk=1): relation "auth_group" does not exist
LINE 1: UPDATE "auth_group" SET "name" = '...

If I rename my fixture to something other than initial_data so that it doesn't get loaded by default, it works, but I don't want to rename my fixtures, because that would mean that I can no longer run loaddata without arguments.

如果我将我的夹具重命名为initial_data以外的其他东西,默认情况下它不会被加载,它可以工作,但我不想重命名我的夹具,因为这意味着我不能再运行不带参数的loaddata。

I have found this bug, but my project does not have any initial migrations. Also, I have other fixtures which are loaded just fine.

我发现了这个错误,但我的项目没有任何初始迁移。另外,我还有其他装载好的装置。

So far, I have tried:

到目前为止,我尝试过:

  • flushing my development database, as well as deleting any possible migration files
  • 刷新我的开发数据库,​​以及删除任何可能的迁移文件
  • deleting and re-creating my virtual env
  • 删除并重新创建我的虚拟环境
  • changing the order of my apps in INSTALLED_APPS
  • 在INSTALLED_APPS中更改我的应用程序的顺序
  • calling the flush command in the .setUp() method.
  • 在.setUp()方法中调用flush命令。

I should mention that I am using the APITestCase from django-rest-framework.

我应该提一下,我正在使用django-rest-framework中的APITestCase。

Any suggestions are welcomed. Thanks.

欢迎任何建议。谢谢。

1 个解决方案

#1


1  

Ok, so finally, it seems that the problem wasn't just when I was testing. When I changed back to running my server, I noticed I was getting the same error.

好吧,最后,似乎问题不仅仅是在我测试的时候。当我改回运行我的服务器时,我注意到我遇到了同样的错误。

Every single similar problem I found had something to do with migrations, but I didn't even had those, because running ./manage.py makemigrations was not generating them.

我发现的每一个类似问题都与迁移有关,但我甚至没有这些问题,因为运行./manage.py makemigrations并没有产生它们。

So I ended up doing ./manage.py makemigrations *app_name* for each of my apps, and everything started working again ...

所以我最终为我的每个应用做了./manage.py makemigrations * app_name *,一切都开始了......

#1


1  

Ok, so finally, it seems that the problem wasn't just when I was testing. When I changed back to running my server, I noticed I was getting the same error.

好吧,最后,似乎问题不仅仅是在我测试的时候。当我改回运行我的服务器时,我注意到我遇到了同样的错误。

Every single similar problem I found had something to do with migrations, but I didn't even had those, because running ./manage.py makemigrations was not generating them.

我发现的每一个类似问题都与迁移有关,但我甚至没有这些问题,因为运行./manage.py makemigrations并没有产生它们。

So I ended up doing ./manage.py makemigrations *app_name* for each of my apps, and everything started working again ...

所以我最终为我的每个应用做了./manage.py makemigrations * app_name *,一切都开始了......