【问题标题】:attempt to write a readonly database - Django app deployed on App Engine (SQLite3 DB)尝试编写只读数据库 - 部署在 App Engine (SQLite3 DB) 上的 Django 应用
【发布时间】:2020-04-09 11:53:46
【问题描述】:

我使用 App Engine 标准环境托管了 Django 应用程序。当我尝试登录时,它给了我 'attempt to write a readonly database' 错误。我已将 URL 添加到 ALLOWED HOSTS 并在 DATABASE 的 settings.py. 中添加了管理员凭据,其他一切都按预期工作。

app.yaml

# [START django_app]
runtime: python37
service: hellotest1

handlers:
# This configures Google App Engine to serve the files in the app's static
# directory.
- url: /static
  static_dir: static/
# This handler routes all requests not caught above to your main app. It is
# required when static routes are defined, but can be omitted (along with
# the entire handlers section) when there are no static files defined.
- url: /.*
  script: auto
# [END django_app]

settings.py - 数据库和 ALLOWED_HOSTS

ALLOWED_HOSTS = ['url']

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'USER': 'admin',
        'PASSWORD': 'admin',

    }
}

【问题讨论】:

    标签: django sqlite google-app-engine


    【解决方案1】:

    AppEngine 实例上的文件系统是只读的(/tmp 目录 iirc 除外)。然而,即使它是可写的,在这种情况下使用 SQLite 也不会长期工作,因为当您部署应用程序的新版本时,会产生一个新实例,但您的数据库(文件)仍保留在旧版本上仅限实例。如果您也有多个实例,这将是一个问题 - 每个实例都需要有自己的数据库。它不会简单地以这种方式工作,您需要创建 Postgres 或 MySQL 的实例。

    【讨论】:

      猜你喜欢
      • 2014-12-07
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2021-11-07
      • 2017-09-27
      • 2017-04-03
      • 1970-01-01
      • 2015-03-24
      相关资源
      最近更新 更多