vue2+Flask網(wǎng)站福稳,輕松部署到免費(fèi)主機(jī)Heroku - 簡(jiǎn)書(shū)
http://www.reibang.com/p/08fab8d4ee35
Heroku免費(fèi)數(shù)據(jù)庫(kù)能存放10000條數(shù)據(jù)rows,如果不小心超了膘婶,Dashboard --> 數(shù)據(jù)庫(kù):會(huì)有提示
Rows: 10685/10000 (Write access revoked)
如上顯示,我的免費(fèi)網(wǎng)站 http://tianya.herokuapp.com诬滩,已經(jīng)有10685條數(shù)據(jù)行了鸯匹,訪問(wèn)就受限了,那怎么刪除已有數(shù)據(jù),恢復(fù)訪問(wèn)呢显歧?不用怕仪或,以下幾步就解決了:
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. 調(diào)用python manage.py來(lái)刪除多余數(shù)據(jù)行
還記得我們上一篇http://www.reibang.com/p/08fab8d4ee35 里的manage.py,這可是遠(yuǎn)程管理應(yīng)用的神器啊
- 遠(yuǎn)程打開(kāi)bash命令行
heroku run bash --app <你的APP名字>
- 運(yùn)行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'>
- 刪除表格內(nèi)的數(shù)據(jù)士骤,這里以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
- 好了范删,多余數(shù)據(jù)都刪除了,再查看一下容量:
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
怎么還是超過(guò)10000翱郊 到旦??
原因是巨缘,后臺(tái)正在刷新添忘,一般需要10分鐘以上,耐心等一會(huì)兒
- 然后就正常了
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. 直接調(diào)用pg:psql操作數(shù)據(jù)庫(kù)
直接命令行heroku pg:psql --app tianya
就可以了若锁,這里就不演示了搁骑。
前提是需要本地安裝 Postgres,不然會(huì)有以下警告:
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)
如果覺(jué)得有幫助乏冀,請(qǐng)給個(gè)小小的贊~~