Schema 创建¶
Schema Creation
这里我们创建一个与 SQLite 数据库客户端的连接,然后发现并初始化模型。
-
async classmethod Tortoise.generate_schemas(safe=
True
)[source] Generate schemas according to models provided to
.init()
method. Will fail if schemas already exists, so it’s not recommended to be used as part of application workflow- Parameters:¶
- safe=
True
¶ When set to true, creates the table only when it does not already exist.
- safe=
- Raises:¶
ConfigurationError – When
.init()
has not been called.- Return type:¶
None
generate_schema
在空数据库上生成架构。
生成架构时还有一个默认选项,即将 safe
参数设置为 True
,这将仅在表不存在时插入表。
Here we create connection to SQLite database client and then we discover & initialize models.
-
async classmethod Tortoise.generate_schemas(safe=
True
)[source] Generate schemas according to models provided to
.init()
method. Will fail if schemas already exists, so it’s not recommended to be used as part of application workflow- Parameters:¶
- safe=
True
¶ When set to true, creates the table only when it does not already exist.
- safe=
- Raises:¶
ConfigurationError – When
.init()
has not been called.- Return type:¶
None
generate_schema
generates schema on empty database.
There is also the default option when generating the schemas to set the safe
parameter to True
which will only insert the tables if they don’t already exist.
帮助函数¶
Helper Functions