Dan Pow Dan Pow - 7 months ago 28
Python Question

sqlalchemy create tables

I am coming form django and I wondered how do I create my tables? In django I run makemigration and migrate. What is the command in sqlalchemy? Do I need to write a special script for that?

Answer

Short answer is db.create_all(). Here is a piece of this answer

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://login:pass@localhost/flask_app'
db = SQLAlchemy(app)
db.create_all()
db.session.commit()