解决platform.sh 环境下,无法打开数据库问题
场景
在platform.sh 执行python manage.py createsuperuser是提示 django.db.utils.OperationalError: unable to open database file 错误
原因
由于settings.py文件中 本地数据库配置在线上配置后,导致本地配置覆盖了线上配置
解决
将线上配置后的DATABASES 配置删掉,重提交代码到platform.sh 即可解决
后续问题
经过上边处理,不在提示找不到数据库文件,但仍有报错:
- django.db.utils.NotSupportedError: PostgreSQL 14 or later is required (found 12.22)
解决:
将services.yaml中的postgresql:12修改成14
- django.db.utils.ProgrammingError: relation "auth_user" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...

解决:
执行数据库迁移
python
python manage.py migrate

再次执行创建超管,顺利创建
python
python manage.py createsuperuser
