为什么我得到一个'ProgrammingError: relation "auth_user"



最近我把一个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的repo,当Django项目运行在1.9.1版本时,DB已经存在了。

我读过:

  • 这个问题。
  • 也是这个

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

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

同样,我认为这是因为DB模式在升级到3.2之前已经存在了。

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

是否有其他方法来解决这个问题,或者强制生成迁移,即使DB已经存在并已同步(并可能伪造它们)?

如果错误是由于迁移造成的,您可以跳过迁移使用以下django库

运行测试时出现错误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/