Peewee Sqlite自动真空吸尘器

2024-04-27 16:36:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法通过peewee设置自动真空选项

运行以下代码段:

from playhouse.sqlite_ext import SqliteExtDatabase, Model, TextField, IntegerField, JSONField

db = SqliteExtDatabase('my_app.db', pragmas=(('cache_size', -1024 * 64), ('journal_mode', 'wal'), ('auto_vacuum', 1)))

class EventLog(Model):
     key = TextField()
     value = JSONField()
     class Meta:
         database = db

EventLog.create_table()

之后:

我已连接到sqlite数据库

sqlite3 my_app.db 
SQLite version 3.22.0 2018-01-22 18:45:57
Enter ".help" for usage hints.
sqlite> PRAGMA auto_vacuum;
0
sqlite> PRAGMA journal_mode;
wal 

为什么自动真空变量不变


Tags: appautodbsqlitemodelmodemyclass
1条回答
网友
1楼 · 发布于 2024-04-27 16:36:40

也许这段来自sqlite Pragma doc[emphasis added]的片段解释了正在发生的事情

The database connection can be changed between full and incremental autovacuum mode at any time. However, changing from "none" to "full" or "incremental" can only occur when the database is new (no tables have yet been created) or by running the VACUUM command. To change auto-vacuum modes, first use the auto_vacuum pragma to set the new desired mode, then invoke the VACUUM command to reorganize the entire database file. To change from "full" or "incremental" back to "none" always requires running VACUUM even on an empty database.**

相关问题 更多 >