DjangoアプリにMySQLを導入したが、それ以降「$ python manage.py migrate」を実行すると、
以下のエラー文が出ます。
python
1$ python manage.py migrate 2 3Traceback (most recent call last): 4 File "manage.py", line 21, in <module> 5 main() 6 File "manage.py", line 17, in main 7 execute_from_command_line(sys.argv) 8 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line 9 utility.execute() 10 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute 11 self.fetch_command(subcommand).run_from_argv(self.argv) 12 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv 13 self.execute(*args, **cmd_options) 14 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute 15 output = self.handle(*args, **options) 16 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped 17 res = handle_func(*args, **kwargs) 18 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 86, in handle 19 executor = MigrationExecutor(connection, self.migration_progress_callback) 20 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/db/migrations/executor.py", line 18, in __init__ 21 self.loader = MigrationLoader(self.connection) 22 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/db/migrations/loader.py", line 49, in __init__ 23 self.build_graph() 24 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/db/migrations/loader.py", line 212, in build_graph 25 self.applied_migrations = recorder.applied_migrations() 26 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 76, in applied_migrations 27 if self.has_table(): 28 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 56, in has_table 29 return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()) 30 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner 31 return func(*args, **kwargs) 32 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/db/backends/base/base.py", line 260, in cursor 33 return self._cursor() 34 File "/Users/masa/fashionrecommend/venv/lib/python3.7/site-packages/django/db/backends/dummy/base.py", line 20, in complain 35 raise ImproperlyConfigured("settings.DATABASES is improperly configured. " 36django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
データベース周りの設定が違うとのことですが、どこがどう違うのかが分からず・・・
どなたかお教えいただけたら幸いです。
settings.py """ Django settings for fashion_app project. Generated by 'django-admin startproject' using Django 3.0.6. For more information on this file, see https://docs.djangoproject.com/en/3.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.0/ref/settings/ """ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 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/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '' # 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', "recommend_app" ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'fashion_app.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.normpath(os.path.join(BASE_DIR, 'templates')),], '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 = 'fashion_app.wsgi.application' import dj_database_url db_from_env = dj_database_url.config() DATABASES = { 'default': dj_database_url.config() } # Database # https://docs.djangoproject.com/en/3.0/ref/settings/#databases # Password validation # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/3.0/topics/i18n/ LANGUAGE_CODE = 'ja' TIME_ZONE = 'Asia/Tokyo' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ] STATIC_ROOT = os.path.join(BASE_DIR, 'fashion_app/static') from socket import gethostname hostname = gethostname() if "masa" in hostname: # デバッグ環境 DEBUG = True #=====ここから...===== import pymysql pymysql.install_as_MySQLdb() DATABASES = { 'default': { #'ENGINE': 'django.db.backends.sqlite3', #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), "ENGINE": "django.db.backends.mysql", "NAME": "sample", "USER": "root", "PASSWORD": "root", "HOST": "127.0.0.1", "PORT": "3306", } } #=====...ここまでは、使用しているデータベースに置き換えてください。===== ALLOWED_HOSTS = [] else: # 本番環境 DEBUG = True LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'console': { 'class': 'logging.StreamHandler', }, }, 'loggers': { 'django': { 'handlers': ['console'], 'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'), }, }, } # DB設定 import dj_database_url PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) db_from_env = dj_database_url.config() DATABASES = { 'default': dj_database_url.config() } ALLOWED_HOSTS = ['*']
local_settings.py import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) import pymysql pymysql.install_as_MySQLdb() DATABASES = { 'default': { #'ENGINE': 'django.db.backends.sqlite3', #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), "ENGINE": "django.db.backends.mysql", "NAME": "sample", "USER": "root", "PASSWORD": "root", "HOST": "127.0.0.1", "PORT": "3306", } } DEBUG = True
あなたの回答
tips
プレビュー