【发布时间】:2021-10-06 15:22:31
【问题描述】:
我将我的 django 应用程序上传到 pythonanywhere,它可以与 sqlite 数据库一起使用,
但是在切换到 mysql 时它不会进行迁移,但是当我朗姆酒时它会迁移管理表python manage.py migrate
这是我的设置应用
import os
from pathlib import Path
import environ
env = environ.Env(
DEBUG=(bool, False)
)
environ.Env.read_env()
DEBUG = env('DEBUG')
BASE_DIR = Path(__file__).resolve().parent.parent
# Raises django's ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')
if DEBUG:
ALLOWED_HOSTS = []
else:
ALLOWED_HOSTS = [
'*',
]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'projects',
'services',
'crispy_forms',
'crispy_bootstrap5',
# should be at bottom
'django_cleanup.apps.CleanupConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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 = 'vectorapp.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [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 = 'vectorapp.wsgi.application'
if not DEBUG:
DATABASES = {
'default': {
'ENGINE': os.getenv("DB_ENGINE"),
'NAME': os.getenv("DB_NAME"),
'USER': os.getenv("DB_USER"),
'PASSWORD': os.getenv("DB_PASSWORD"),
'HOST': os.getenv("DB_HOST"),
# 'PORT': os.getenv("DB_PORT"),
"OPTIONS": {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1",
'charset': 'utf8mb4',
"autocommit": True,
}
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
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
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
# STATIC_ROOT = 'static_root'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media/')
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
if not DEBUG:
DEFAULT_FILE_STORAGE = 'backend.storage.AzureMediaStorage'
STATICFILES_STORAGE = 'backend.storage.AzureStaticStorage'
SECRET_KEY = env("SECRET_KEY")
AZURE_ACCOUNT_NAME = env("AZURE_ACCOUNT_NAME")
AZURE_CONNECTION_STRING = env("AZURE_CONNECTION_STRING")
AZURE_ACCOUNT_KEY = env("AZURE_ACCOUNT_KEY")
AZURE_URL_EXPIRATION_SECS = int(env("AZURE_URL_EXPIRATION_SECS"))
# custom
AZURE_MEDIA_CONTAINER = env("AZURE_MEDIA_CONTAINER")
AZURE_STATIC_CONTAINER = env("AZURE_STATIC_CONTAINER")
我在这里做错了什么? 我使用了各种数据库,但它仍然说当我尝试迁移时没有检测到任何变化
【问题讨论】:
-
更改数据库设置不会更改迁移,因为这些迁移是以“方言不变风格”进行的。
-
尝试在数据库中用 msql 替换 sqlite
标签: python django mysql-python django-migrations pythonanywhere