2017-09-21 27 views
0

我在谷歌應用引擎上部署了一個帶有django-backend的網站。我跟着他們的tutorial。我已經使用MySQL在本地服務器上運行了該網站,並且它運行完美。 當谷歌App Engine上部署它,它給了我下面的錯誤:Google App Engine,Django:部署後Google雲SQL中沒有製作表格

​​

這裏是我的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/.*$ 

這裏是我的settings.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引擎。提前致謝!

回答

1

你說你按照步驟操作。當您創建並運行遷移時,您是否運行了Cloud SQL Proxy?如果它沒有運行或配置不正確,這就可以解釋爲什麼你的遷移在你的本地數據庫中運行良好,但沒有在雲數據庫中應用。

+1

'cloud_sql_proxy.exe -instances =「[YOUR_INSTANCE_CONNECTION_NAME]」= tcp:3306' 「此步驟建立從本地計算機到本地計算機的Cloud SQL實例的連接測試目的。保持Cloud SQL Proxy在整個測試應用程序的本地時間運行。「 它說,只有當您必須在本地測試您的應用程序時,您才需要使用Cloud SQL Proxy – Maverick7

+0

謝謝!你是對的! Google需要使文檔更清晰。 – Maverick7

0
  1. 從Google sql控制檯中刪除數據庫。
  2. 刪除所有的遷移和重新創建遷移python manage.py makemigrations
  3. python manage.py migrate
  4. 再次部署應用程序和測試。
+0

我照你說的做了......但是我仍然得到相同的錯誤。當我進行遷移和遷移時,它在我的本地數據庫上創建新的遷移,而不是在Google雲端數據庫上,並且當我使用' gcloud應用程序部署'它正在部署與以前一樣的東西.. – Maverick7

相關問題