Google App Engine,Django:部署后,桌子不是在Google Cloud SQL中制作的



我正在使用Google App Engine上的Django-Backend部署网站。我遵循他们的教程。我已经使用MySQL在本地服务器上运行该网站,并且运行完美。在Google App Engine上部署它时,它会给我以下错误:

ProgrammingError "Table 'clouddatabasename'.'appname'_'modelname' doesn't exist"

这是我的app.yaml:

# [START django_app]
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /static
  static_dir: static/
- url: .*
  script: wt.wsgi.application
# Only pure Python libraries can be vendored
# Python libraries that use C extensions can
# only be included if they are part of the App Engine SDK 
# Using Third Party Libraries: https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27
libraries:
- name: MySQLdb
  version: 1.2.5
- name: django
  version: "1.11"
env_variables:
    CLOUDSQL_CONNECTION_NAME: 'copied perfectly from google cloud sql instance'
    CLOUDSQL_USER: username
    CLOUDSQL_PASSWORD: password
# [END django_app]
# Google App Engine limits application deployments to 10,000 uploaded files per
# version. The skip_files section allows us to skip virtual environment files
# to meet this requirement. The first 5 are the default regular expressions to
# skip, while the last one is for all env/ files.
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?..*$
- ^env/.*$

这是我的设置.py:

if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'database_name',
            'USER': 'user_name',
            'PASSWORD': 'password',
             'HOST': '/cloudsql/copied perfectly from google cloud sql instance',
        }
    }
else:
    DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.mysql',
                'HOST': '127.0.0.1',
                'PORT': '3306',
                'NAME': 'database_name',
                'USER': 'username',
                'PASSWORD': 'password',
                        }
                }           

请帮助我。我不知道为什么我的型号/桌子在Google App Engine上不可用。预先感谢!

您说您遵循步骤。当您进行迁移并运行迁移时,您是否运行了Cloud SQL代理?如果它没有运行或未正确配置,这可以解释为什么您的迁移在本地数据库中正常运行,但在云数据库中不应用。

  1. 从Google SQL控制台中删除数据库。
  2. 删除所有迁移,然后再次创建迁移python manage.py makemigrations
  3. python manage.py migrate
  4. 部署您的应用程序并再次测试。

相关内容

  • 没有找到相关文章