[英]Flask-SQLAlchemy: Do I have to create_all if tables existed already?
In the example , it doesn't specify that when and how to execute create_all
. 在该示例中 ,它没有指定何时以及如何执行
create_all
。
SQLAlchemy.create_all() method to create the tables and database
SQLAlchemy.create_all()方法创建表和数据库
Suppose I have already created database and tables (also contains data already) in advance, do I still have to execute create_all
? 假设我已经预先创建了数据库和表(也已经包含数据),是否还需要执行
create_all
?
No you don't. 不,你不会。 There are some advantages to using
create_all
in that you can quickly create production and test environments based on the database models that you have made. 使用
create_all
有一些优点,因为您可以根据所建立的数据库模型快速创建生产和测试环境。 create_all
also prevents having your models not match the actual database since the database was made from the models. 由于数据库是由模型创建的,因此
create_all
还可以防止模型与实际数据库不匹配。
But if you already have the tables created and data already there, it is not required, although it is a good practice and had some advantages. 但是,如果您已经创建了表并且已经在其中创建了数据,则这不是必需的,尽管这是一种很好的做法并且具有一些优点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.