简体   繁体   English

如何使用flask-sqlalchemy更新Postgres模式?

[英]How to update a Postgres schema with flask-sqlalchemy?

I'm running a simple Flask app with Heroku, and I can run the following command to create all the tables: 我正在用Heroku运行一个简单的Flask应用程序,并且可以运行以下命令来创建所有表:

db.create_all()

However, I ship new stuff frequently and I often need to add new columns to existing tables. 但是,我经常运送新东西,并且经常需要向现有表中添加新列。 Is there an easy way to do this? 是否有捷径可寻?

If I need to manually create a new column with Postgres, how would I access the repl for Heroku's Postgres database? 如果需要使用Postgres手动创建新列,我将如何访问Heroku的Postgres数据库的repl?

You should be using migrations. 您应该使用迁移。

This is a great plugin for that: https://flask-migrate.readthedocs.io/en/latest/ 这是一个很棒的插件: https : //flask-migrate.readthedocs.io/en/latest/

and this is a good explanation about how to get going with that: https://realpython.com/flask-by-example-part-2-postgres-sqlalchemy-and-alembic/ 这是有关如何进行此操作的很好的解释: https : //realpython.com/flask-by-example-part-2-postgres-sqlalchemy-and-alembic/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM