Vue2 + Flask website, easy deployment to free hosting Heroku – Jane books at http://www.jianshu.com/p/08fab8d4ee35

Rows:        10685/10000 (Write access revoked)
Copy the code

As above, according to my free web site, http://tianya.herokuapp.com, already has 10685 rows of data, access is limited, that how to delete existing data, restore access? Don’t be afraid, the following steps will solve:

1. Install the 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

Choose either 2a or 2B below

2a. Call Python manage.py to remove excess rows

Remember when we in the previous http://www.jianshu.com/p/08fab8d4ee35 in the manage. Py, it’s a remote management applications artifact

  • Remotely open the bash command lineHeroku run bash --app < your app name >
  • Run the 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'>
Copy the code
  • Delete the data in the table, using Logs as an example
>>> 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
Copy the code
  • Ok, the excess data has been deleted, and then check the capacity:
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
Copy the code

Why is it still more than 10000? The reason is that the background is refreshing, generally need more than 10 minutes, patient wait for a while

  • And then it’s normal
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
Copy the code

2B. Directly call PG: PSQL to operate database

Heroku pg: PSQL –app tianya will do.

Postgres must be installed locally, otherwise the following warnings will appear:

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
Copy the code

3. View tables

The table is defined in your Flask Model, look it up in the source file. Alternatively, you can use the command line. Check the Postreg URI (Database –> Settings –> View Credentials) on the Heroku Dashboard

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)
Copy the code

If you find it helpful, please give a small thumbs-up