【问题标题】:Database keeps reverting to previous date数据库不断恢复到以前的日期
【发布时间】:2014-07-08 02:59:34
【问题描述】:

所以,我写这篇文章的前提是我很清楚你会询问更多信息,但我还不知道该说什么。

我有一个 django 应用程序,它为个人网站提供动力,它有一个简单的留言板,供人们给我留言,告诉我我有多棒。现在,总的来说,我在使用这个应用程序时遇到了很多麻烦,并且来回经历了很多 git-ness,我猜这可能是导致这个问题的原因。

不知何故,我的数据不断被我的数据库的特定快照替换。今天早上我检查它时,它有十条旧的虚拟测试消息,还有一条新的真实消息。我回复了新的真实的,删除了虚拟测试的,一切看起来都很好。那天我没有再碰过这个应用程序。刚才再去查的时候,新消息不见了,假消息又回来了。

它通过 Heroku 部署并使用 Python 2.7 和 Django 1.6 编写。该网站位于 www.wienerwedding.com/guestbook/。

这是我的 settings.py 文件,这是我对可能存在问题的唯一猜测。 如果你告诉我看什么可能有帮助,我会把它包括在内。

# Django settings for wedding project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    ('xxx', 'xxxx@gmail.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {

        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'wedding.db',


    }
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['*']

    # Parse database configuration from $DATABASE_URL
if(DEBUG != True):
    import dj_database_url
    DATABASES['default'] =  dj_database_url.config()

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')


TIME_ZONE = 'America/New_York'

LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True

USE_L10N = True

USE_TZ = True


MEDIA_ROOT = '/Users/paulnichols/code/wedding/mainsite/static/images/photoalbum/'

MEDIA_URL = 'http://127.0.0.1:8000/photos/'

import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'mainsite/static/'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
       os.path.join(BASE_DIR, 'staticfiles'),
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'xxxxxxxx'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django_user_agents.middleware.UserAgentMiddleware',
)

ROOT_URLCONF = 'wedding.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'wedding.wsgi.application'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    'mainsite/templates',
    'quiz/templates',
    'photoalbum/templates',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    'mainsite',
    'quiz',
    'photoalbum',
    'django_google_maps',
    'django_user_agents',
    'south',
)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

【问题讨论】:

  • wedding.db 文件是否有机会被 git 跟踪?如果是这样,您可能想停止跟踪它。

标签: python django heroku


【解决方案1】:

您已将 DEBUG 设置为 True,根据该代码,这意味着您将始终使用可能与您的应用程序一起上传的 sqlite db 文件,而不是 Heroku 的 Postgres 设置。确保 DEBUG 为 false,和/或使用另一个环境变量来确定是否使用开发数据库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 2014-06-21
    • 2010-11-01
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多