Why am I getting a 'ProgrammingError: relation "auth_user" does not exist' exception when running tests?

Why am I getting a 'ProgrammingError: relation "auth_user" does not exist' exception when running tests?

最近我将一个 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

我明白这是因为目前我没有任何 'migrations' 目录,因为我克隆了 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/