简体   繁体   English

OperationalError:尝试在 Google Cloud 应用程序上写入只读数据库

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

Recently, I have been trying to deploy an interactive Google App Engine that writes to a SQLite database, which works fine when running the app locally, but when running it through the server, I receive the error:最近,我一直在尝试部署一个交互式 Google App Engine,它写入 SQLite 数据库,在本地运行应用程序时工作正常,但是通过服务器运行它时,我收到错误:

OperationalError: attempt to write a readonly database

I tried changing the permissions on my .db , .sql but no luck.我尝试更改我的.db.sql的权限,但没有运气。

Any advice would be greatly appreciated.任何建议将不胜感激。

You can try changing permission of the directory and checking that.sqllite file exists and is writable您可以尝试更改目录的权限并检查.sqllite 文件是否存在并且可写

But generally speaking is 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但一般来说,在应用程序引擎上工作时依赖磁盘数据并不是一个好主意,因为磁盘存储是短暂的(除非您在 flex 上使用永久性磁盘),但即便如此,最好使用云数据库解决方案

App Engine has exactly read-only file system, ie no files can be modified. App Engine 具有完全只读的文件系统,即不能修改任何文件。 It has, however, /tmp/ folder to store temporary files as the name suggests.但是,顾名思义,它有 /tmp/ 文件夹来存储临时文件。 It actually uses RAM, so not a good idea if the database is huge.它实际上使用 RAM,所以如果数据库很大,这不是一个好主意。

On app startup you can copy your original database file to /tmp/ folder and use it from there afterwards.在应用程序启动时,您可以将原始数据库文件复制到 /tmp/ 文件夹,然后从那里使用它。

This works.这行得通。 However, all the changes in the database are lost when the app nodes scale to 0. Each node of the app has its own database copy and the data is not shared between the nodes.但是,当应用节点扩展到 0 时,数据库中的所有更改都会丢失。应用的每个节点都有自己的数据库副本,并且节点之间不会共享数据。 If you need the data to be shared between the app nodes, better use CloudSQL.如果您需要在应用节点之间共享数据,最好使用 CloudSQL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM