Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有用于使用 sqlalchemy ORM 为烧瓶加载初始数据(并将数据转储到 json)的工具?类似于 django 的 loaddata 和 dumpdata。
不,没有。您必须使用所用数据库的工具。特别是 PostgreSQL 的实用程序非常通用,比 Django 的要多得多。
但是,如果您真正的问题只是“如何将一些初始数据放入数据库”,例如在开发时,那么您可以执行以下操作:
def init_db(): if db_session.query(User).count() == 0: admin = User("admin", "admin") db_session.add(admin) db_session.commit()