Paste_Image.pngvue2+Flask网站,轻松部署到免费主机Heroku - 简书
http://www.jianshu.com/p/08fab8d4ee35
Heroku免费数据库能存放10000条数据rows,如果不小心超了,Dashboard --> 数据库:会有提示
Rows: 10685/10000 (Write access revoked)
如上显示,我的免费网站 http://tianya.herokuapp.com,已经有10685条数据行了,访问就受限了,那怎么删除已有数据,恢复访问呢?不用怕,以下几步就解决了:
1. 安装Heroku CLI
https://devcenter.heroku.com/articles/getting-started-with-python#set-up
https://oneclient.sfx.ms/Win/Direct/17.3.6943.0625/OneDriveSetup.exe
以下2a, 2b任选其一
2a. 调用python manage.py来删除多余数据行
还记得我们上一篇http://www.jianshu.com/p/08fab8d4ee35 里的manage.py,这可是远程管理应用的神器啊
- 远程打开bash命令行
heroku run bash --app <你的APP名字>
- 运行manage.py shell
PS H:\> heroku run bash --app tianya
Running bash on tianya... up, run.4914 (Free)
~ $ python manage.py shell
>>> app
<Flask 'app'>
- 删除表格内的数据,这里以Logs表格为例
>>> from app.models import Logs
>>> s = db.session
>>> s.query(Logs).count()
9989L
>>> s.query(Logs).filter(Logs.id>100).delete()
>>> s.commit()
>>> s.query(Logs).count()
100L
- 好了,多余数据都删除了,再查看一下容量:
PS H:\> heroku pg --app tianya
=== DATABASE_URL, HEROKU_POSTGRESQL_BRONZE_URL
Plan: Hobby-dev
Status: Available
Connections: 2/20
PG Version: 9.5.5
Created: 2016-10-18 06:16 UTC
Data Size: 20.5 MB
Tables: 11
Rows: 10685/10000 (Write access revoked) - refreshing
Fork/Follow: Unsupported
Rollback: Unsupported
Add-on: postgresql-adjacent-xxx
怎么还是超过10000啊??
原因是,后台正在刷新,一般需要10分钟以上,耐心等一会儿
- 然后就正常了
PS H:\> heroku pg:info --app tianya
=== DATABASE_URL, HEROKU_POSTGRESQL_BRONZE_URL
Plan: Hobby-dev
Status: Available
Connections: 3/20
PG Version: 9.5.5
Created: 2016-10-18 06:16 UTC
Data Size: 20.5 MB
Tables: 11
Rows: 1459/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Add-on: postgresql-adjacent-xxx
2b. 直接调用pg:psql操作数据库
直接命令行heroku pg:psql --app tianya
就可以了,这里就不演示了。
前提是需要本地安装 Postgres,不然会有以下警告:
PS H:\> heroku pg:psql --app tianya
--> Connecting to postgresql-adjacent-41730
! The local psql command could not be located. For help installing psql, see
! https://devcenter.heroku.com/articles/heroku-postgresql#local-setup
3.查看有哪些table
table是在你的Flask model里定义的,查源文件即可。
另外,用命令行也可以。
先在Heroku Dashboard上查一下postreg URI(Database --> Settings --> View Credentials)
from sqlalchemy import MetaData
m = MetaData()
from sqlalchemy import create_engine
engine = create_engine("postgresql://<URI>")
m.reflect(engine)
for table in m.tables.values():
print(table.name)
for column in table.c:
print(column.name)
如果觉得有帮助,请给个小小的赞~~
网友评论