【django.db.utils.OperationalError: unable to open database file】

解决platform.sh 环境下,无法打开数据库问题

场景

在platform.sh 执行python manage.py createsuperuser是提示 django.db.utils.OperationalError: unable to open database file 错误

原因

由于settings.py文件中 本地数据库配置在线上配置后,导致本地配置覆盖了线上配置

解决

将线上配置后的DATABASES 配置删掉,重提交代码到platform.sh 即可解决

后续问题

经过上边处理,不在提示找不到数据库文件,但仍有报错:

  1. django.db.utils.NotSupportedError: PostgreSQL 14 or later is required (found 12.22)
解决:

将services.yaml中的postgresql:12修改成14

  1. 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
感受:终于解决了这个问题,搞了两三天,本想跳过,但不解决就难受的狠,不知道其他人有没有这种感觉,哈哈!
相关推荐
郝学胜_神的一滴1 分钟前
Effective Python 条款 8: 同时遍历多组序列:zip 与 zip_longest 的实战避坑指南
python·pycharm
盛世宏博智慧档案4 分钟前
高速 ETC 门架外场机房温湿度远程监测解决方案
服务器·数据库·php·高度·高速·温湿度
—Miss. Z—6 分钟前
计算机三级数据库技术—应用题2️⃣
数据库·mysql
PrudentWoo9 分钟前
PostgreSQL 12 登录失败:role “postgres“ is not permitted to log in 的排查与修复
数据库·postgresql
承渊政道11 分钟前
【Python编程—从入门到实践】(Python字典:从基础语义到现代工程实践)
开发语言·python·pycharm·字典·嵌套
麻雀飞吧13 分钟前
搜索“近期量化入门”时,先补交易理解再看 Python 和 API
人工智能·python
这个DBA有点耶21 分钟前
临时表从4.7秒到0.12秒:不是所有Using temporary都需要优化
数据库·mysql·代码规范
天衍四九-22 分钟前
排查慢SQL用explain分析执行计划,主要关注哪些字段?
数据库·sql
Meta3941 分钟前
PostgreSQL报SELECT rule‘s target entry X has different type from column “XXX“
数据库·postgresql·dubbo
名字还没想好☜1 小时前
Python 字符编码实战:encode/decode、UnicodeDecodeError 与 open 的 encoding 坑
开发语言·后端·python·编程语言