python - django 部署到heroku 如何删除数据库
巴扎黑
巴扎黑 2017-04-17 15:21:26
[Python讨论组]

model 中新增了一个对象 Message 和 并在另一个model中增加外键字段message,然后push到heroku上,同步migrate之后,发现新的表不能用. 但是本地是执行 python manage.py flush 之后同步的,没出问题, 但是在heroku上执行 flush 出错

CommandError: Database d4e4561s5hscht couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin sqlflush'. That's the SQL this command wasn't able to run.
The full error: cannot truncate a table referenced in a foreign key constraint
DETAIL:  Table "blog_post" references "auth_user".
HINT:  Truncate table "blog_post" at the same time, or use TRUNCATE ... CASCADE.

请问怎么清理数据库

巴扎黑
巴扎黑

全部回复(1)
PHP中文网

「blog_post」表中有字段外键关联到了 「auth_user」 表。
flush是truncate table的,auth_user表有数据当然不能truncate。

现版本通常的做法是:

python manage.py makemigrations
python manage.py migrate

这样就可以了啊,不知道LZ说的「migrate之后,新的表不能用」是什么意思

为什么要flush呢? 都已经上线了 还要清数据?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号