Я пытаюсь запустить Django командыНе удается запустить manage.py против Google Cloud SQL
manage.py makemigrations
manage.py migrate
для установки баз данных MySQL на goodle облачного SQL, но он работает только на моем локальном сервере разработки.
Я следил за кодом в linked StackExchange thread.
Поскольку это не работает, я вынужден базу данных в облако SQL лишь определяя, что базы данных в settings.py и я получаю следующее:
Traceback (most recent call last):
File "C:\FCA\manage.py", line 24, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 398, in execute
self.check()
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "C:\Python27\lib\site-packages\django\core\checks\registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Python27\lib\site-packages\django\core\checks\model_checks.py", line 28, in check_all_models
errors.extend(model.check(**kwargs))
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 1170, in check
errors.extend(cls._check_fields(**kwargs))
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 1247, in _check_fields
errors.extend(field.check(**kwargs))
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 925, in check
errors = super(AutoField, self).check(**kwargs)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 208, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 317, in _check_backend_specific_checks
return connections[db].validation.check_field(self, **kwargs)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\validation.py", line 18, in check_field
field_type = field.db_type(connection)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 625, in db_type
return connection.data_types[self.get_internal_type()] % data
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 184, in data_types
if self.features.supports_microsecond_precision:
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\features.py", line 53, in supports_microsecond_precision
return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 359, in mysql_version
with self.temporary_connection():
File "C:\Python27\lib\contextlib.py", line 17, in __enter__
return self.gen.next()
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 564, in temporary_connection
cursor = self.cursor()
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 204, in _cursor
self.ensure_connection()
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Python27\lib\site-packages\django\db\utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 264, in get_new_connection
conn = Database.connect(**conn_params)
File "build\bdist.win-amd64\egg\MySQLdb\__init__.py", line 81, in Connect
File "build\bdist.win-amd64\egg\MySQLdb\connections.py", line 193, in __init__
django.db.utils.OperationalError: (1045, "Access denied for user 'thwaites'@'localhost' (using password: YES)")
Я получил адрес IPv4 от Google и пользователь/пароль доступа при подключении с MySQL Workbench
EDIT - ниже я прикрепил settings.py
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.8.5.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '-c&qt=71oi^e5s8(ene*$b89^#%*0xeve$x_trs91veok9#0h0'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'coursework',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
# [START db_setup]
# set this if you want to run django commands from development against CloudSQL eg to set up database etc
#make_cloudsql = 'prod'
import os
"""
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
# Running on production App Engine, so use a Google Cloud SQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/quizalitious:myfcacoursedb',
'NAME': 'mydb',
'USER': 'root',
}
}
elif os.getenv('SETTINGS_MODE') == 'prod':
""" # Running in development, but want to access the Google Cloud SQL instance in production.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'INSTANCE': '173.194.228.69',
'NAME': 'mydb',
'USER': 'thwaites',
'PASSWORD' : 'secret',
}
}
"""else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb',
'USER': 'root',
'PASSWORD': 'secret',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {
'autocommit': True,
}
}
}
"""
# [END db_setup]
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_ROOT='static'
STATIC_URL = '/static/'
MEDIA_ROOT='media'
MEDIA_URL = '/media/'
Привет, Можете ли вы опубликовать свои настройки.py? – SBillion
Я думаю, '' INSTANCE ': 'должно быть' 'HOST': ' –
Vadim
P.S. Вы должны изменить свой SECRET_KEY, так как вы разместили его в общественном месте ... – Vadim