OperationalError: Attempt to Write A ReadOnly Database on Google Cloud Application

OperationalError: Attempt to Write A ReadOnly Database on Google Cloud Application

最近,我一直在尝试部署一个写入 SQLite 数据库的交互式 Google App Engine,当 运行 在本地应用程序时它工作正常,但当 运行 它时通过服务器,我收到错误:

OperationalError: attempt to write a readonly database

我尝试更改 .db.sql 的权限,但没有成功。

如有任何建议,我们将不胜感激。

您可以尝试更改 and checking that .sqllite file exists and is writable

的权限

不过一般来说是not a good idea to rely on disk data when working on app engine as disk storage is ephemeral (unless you are using persistent disks on flex) but even then its better to use a cloud database solution

App Engine 具有完全只读的文件系统,即无法修改任何文件。但是,顾名思义,它有 /tmp/ 文件夹来存储临时文件。它实际上使用 RAM,所以如果数据库很大,这不是一个好主意。

在应用程序启动时,您可以将原始数据库文件复制到 /tmp/ 文件夹,然后从那里使用它。

这行得通。但是,当应用程序节点缩放到 0 时,数据库中的所有更改都会丢失。应用程序的每个节点都有自己的数据库副本,并且数据不会在节点之间共享。如果您需要在应用程序节点之间共享数据,最好使用 CloudSQL。