最近我将一个 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 repo 并且当 Django 项目在 1.9.1 版中运行时数据库已经存在。
我读了:
他们都建议运行迁移,但是:
# python manage.py makemigrations
No changes detected
# python manage.py makemigrations auth
No changes detected in app 'auth'
同样,我认为这是因为数据库模式在升级到 3.2 之前就已经存在。
我似乎无法解决运行迁移方法的问题。
是否有另一种方法来解决此问题,或者即使数据库已经存在并且已同步(并且可能伪造它们),也可以强制生成迁移?