django - 为什么我在运行测试时收到 'ProgrammingError: relation "auth_user“不存在”异常?

标签 django django-tests django-3.2

最近我将 Django 项目从版本 1.9.1 迁移到了 3.2.7。

现在我正在尝试编写一些新测试,但收到此错误:

# python manage.py test
Creating test database for alias 'default'...
Got an error creating the test database: database "test_django" already exists

Type 'yes' if you would like to try deleting the test database 'test_django', or 'no' to cancel: yes
Destroying old test database for alias 'default'...
Traceback (most recent call last):
  File "/opt/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "auth_user" does not exist

我理解这是因为目前我没有任何“迁移”目录,因为我克隆了 git 存储库,并且当 Django 项目在版本 1.9.1 中运行时数据库已经存在。

我读过:

他们都建议运行迁移,但是:

# python manage.py makemigrations 
No changes detected
# python manage.py makemigrations auth
No changes detected in app 'auth'

我再次认为这是因为数据库架构在升级到 3.2 之前就已经存在了。

我似乎无法解决运行迁移方法的问题。

是否有其他方法可以解决此问题,或者强制生成迁移,即使数据库已经存在并且已同步(并且可能是伪造的)?

最佳答案

If the error is because of the migrations you can skip the migration errors while running tests by using the following django library

django-test-without-migrations ( pip install django-test-without-migrations)

安装库并将其添加到 INSTALLED_APPS (settings.py)

Then run, python manage.py test --nomigrations 

引用:https://pypi.org/project/django-test-without-migrations/

关于django - 为什么我在运行测试时收到 'ProgrammingError: relation "auth_user“不存在”异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69495933/

相关文章:

python - 如何在 AJAX 调用中使用 django-debug-toolbar?

django - django 测试是否有一个类似于 setUp() 的breakDown(),在所有测试完成后运行?

python - Django 测试,断言 CSV 内容存在

python - Django:保持 setUpTestData 干燥

django rest api __init__() 接受 1 个位置参数,但给出了 2 个

python - 无法登录我的用户,他们似乎没有正确注册

python - Django:用户信息分为 "User"和 "Person"模型

django - 如何在 Django 模板中引用选择列表?

python-3.x - django.db.utils.NotSupportedError : extension "postgis" is not available