SHARE
TWEET

Untitled

a guest Oct 16th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Migrations
  2.  
  3. ### Flask-Migrate, migrations with Alembic
  4. $ pip install Flask-Migrate
  5.  
  6. And on our `main.py` import and add Migrate
  7. ```python
  8. from flask_migrate import Migrate
  9. from config import DevConfig
  10.  
  11. app = Flask(__name__)
  12. app.config.from_object(DevConfig)
  13.  
  14. db = SQLAlchemy(app)
  15. migrate = Migrate(app, db)
  16. ```
  17.  
  18. > (Optinally) Tell Flask where is the app  
  19. $ export FLASK_APP=main.py  
  20. $ flask db
  21.  
  22. tracking changes (create `migrations` folder)  
  23. $ flask db init
  24.  
  25. begin stored changes in `migrations/versions/`  
  26. $ flask db migrate -m"initial migration"
  27.  
  28. $ flask db upgrade --sql  
  29. $ flask db upgrade
  30.  
  31. $ flask db history  
  32. $ flask db downgrade number_hash
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top