sqlalchemy创建表 [英] sqlalchemy create tables

查看:113
本文介绍了sqlalchemy创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Django来,我想知道如何创建表格?在Django中,我运行makemigration并进行迁移。 sqlalchemy中的命令是什么?我是否需要为此编写特殊的脚本?

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?

推荐答案

简短的答案是 db.create_all() 。这是答案的一部分

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()

这篇关于sqlalchemy创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆