Python 我不知道';我不知道如何解决这个问题;数据库操作&x27;错误:对象没有属性';选择';

Python 我不知道';我不知道如何解决这个问题;数据库操作&x27;错误:对象没有属性';选择';,python,django,heroku,postgis,Python,Django,Heroku,Postgis,我正试图在Heroku上用PostGIS建立一个GeoDjango网站。我一直在尝试谷歌这个属性,但我找不到信息或解决方案。尝试使用heroku run python manage.py migrate进行迁移或迁移数据库时,会返回此错误 AttributeError:“DatabaseOperations”对象没有属性“select” 我在当地没有问题。我按照Heroku上的说明创建了数据库扩展。及 有没有人能帮我解决问题。我没有在Heroku上正确配置数据库吗 多谢各位 我的网站设置.py

我正试图在Heroku上用PostGIS建立一个GeoDjango网站。我一直在尝试谷歌这个属性,但我找不到信息或解决方案。尝试使用
heroku run python manage.py migrate进行迁移或迁移数据库时,会返回此错误

AttributeError:“DatabaseOperations”对象没有属性“select”

我在当地没有问题。我按照Heroku上的说明创建了数据库扩展。及

有没有人能帮我解决问题。我没有在Heroku上正确配置数据库吗

多谢各位

我的网站设置.py

"""
Django settings for my_site project on Heroku. For more info, see:
https://github.com/heroku/heroku-django-template

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/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

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django.contrib.gis',
    'storages',
    'easy_thumbnails',
    'image_cropping',
    'architecture',
    'blog',
]

MIDDLEWARE_CLASSES = [
    '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.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'my_site.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',
            ],
            'debug': DEBUG,
        },
    },
]

WSGI_APPLICATION = 'my_site.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'heroku_my_site',
        'USER': 'postgres',
        'PASSWORD': 'password',
        'HOST': 'localhost',
    }
}

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/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Copenhagen'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, 'static'),
]

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'uploads')
MEDIA_URL = '/media/'

# Amazon S3 configuration
# Add MY_SECRET_KEY, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to your Heroku config vars
if not DEBUG:
    MY_SECRET_KEY = os.environ.get('MY_SECRET_KEY')
    AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
    AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
    AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
    ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

# Easy thumbnails
from easy_thumbnails.conf import Settings as easy_thumbnail_settings
THUMBNAIL_PROCESSORS = (
    'image_cropping.thumbnail_processors.crop_corners',
)
THUMBNAIL_PROCESSORS += easy_thumbnail_settings.THUMBNAIL_PROCESSORS

IMAGE_CROPPING_SIZE_WARNING = True
# size is "width x height"
IMAGE_CROPPING_THUMB_SIZE = (300, 300)


$heroku运行python manage.py迁移
在上运行python manage.py迁移⬢ 我的网站。。。启动,运行0.8591(免费)
回溯(最近一次呼叫最后一次):
文件“manage.py”,第10行,在
从命令行(sys.argv)执行命令
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/management/_init__.py”,第367行,从命令行执行
utility.execute()
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/management/_init__.py”,执行中第359行
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py”,第294行,运行于
self.execute(*args,**cmd_选项)
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/management/base.py”,执行中的第342行
self.check()
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/management/base.py”,第374行,选中
包括部署检查=包括部署检查,
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/management/commands/migrate.py”,第62行,在运行检查中
问题。扩展(超级(命令,自我)。\运行检查(**kwargs))
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/management/base.py”,第361行,在运行检查中
返回检查。运行检查(**kwargs)
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/checks/registry.py”,运行检查中的第81行
新建错误=检查(应用程序配置=应用程序配置)
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/checks/url.py”,check\u url\u config中的第14行
返回检查\u分解器(分解器)
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/checks/url.py”,第24行,在check\u解析器中
对于resolver.url\u模式中的模式:
文件“/app/.heroku/python/lib/python3.6/site packages/django/utils/functional.py”,第35行,在__
res=instance.\uuuu dict\uuuu[self.name]=self.func(实例)
文件“/app/.heroku/python/lib/python3.6/site packages/django/url/resolvers.py”,第313行,url_模式
patterns=getattr(self.urlconf_模块,“urlpatterns”,self.urlconf_模块)
文件“/app/.heroku/python/lib/python3.6/site packages/django/utils/functional.py”,第35行,在__
res=instance.\uuuu dict\uuuu[self.name]=self.func(实例)
文件“/app/.heroku/python/lib/python3.6/site packages/django/url/resolvers.py”,第306行,在urlconf_模块中
返回导入_模块(self.urlconf_名称)
文件“/app/.heroku/python/lib/python3.6/importlib/_init__.py”,第126行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
文件“”,第978行,在_gcd_import中
文件“”,第961行,在“查找”和“加载”中
文件“”,第950行,在“查找”和“加载”中解锁
文件“”,第655行,已加载
exec_模块中第678行的文件“”
文件“”,第205行,在调用中删除了帧
文件“/app/my_site/url.py”,第23行,在
从architecture.views导入地图数据
文件“/app/architecture/views.py”,第24行,在
字段=('point','project','slug',),stream=out)
文件“/app/.heroku/python/lib/python3.6/site packages/django/core/serializers/base.py”,第79行,在serialize中
对于计数,枚举中的obj(queryset,start=1):
文件“/app/.heroku/python/lib/python3.6/site packages/django/db/models/query.py”,第256行,在__
self._fetch_all()
文件“/app/.heroku/python/lib/python3.6/site packages/django/db/models/query.py”,第1087行,在_fetch_all中
self.\u result\u cache=list(self.iterator())
文件“/app/.heroku/python/lib/python3.6/site packages/django/db/models/query.py”,第54行,在__
结果=编译器。执行_sql()
文件“/app/.heroku/python/lib/python3.6/site packages/django/db/models/sql/compiler.py”,第824行,在execute\u sql中
sql,params=self.as_sql()
as_sql中的文件“/app/.heroku/python/lib/python3.6/site packages/django/db/models/sql/compiler.py”,第369行
extra\u select、order\u by、group\u by=self.pre\u sql\u setup()
文件“/app/.heroku/python/lib/python3.6/site packages/django/db/models/sql/compiler.py”,第46行,在预sql设置中
self.setup\u查询()
文件“/app/.heroku/python/lib/python3.6/site packages/django/db/models/sql/compiler.py”,第37行,在setup\u查询中
self.select、self.klass\u info、self.annotation\u col\u map=self.get\u select()
文件“/app/.heroku/python/lib/python3.6/site packages/django/db/models/sql/compiler.py”,第226行,在get_select中
ret.append((col,self.compile(col,select\u format=True),别名))
compile中的文件“/app/.heroku/python/lib/python3.6/site packages/django/db/models/sql/compiler.py”,第355行
返回节点。输出\字段。选择\格式(self、sql、params)
文件“/app/.heroku/python/lib/python3.6/site packages/django/contrib/gis/db/models/fields.py”,第64行,select_格式
如果connection.ops.select:
AttributeError:“DatabaseOperations”对象没有属性“select”

在运行
数据库['default']之后,检查
数据库['default']['ENGINE']
是否正确设置。更新(db\u from_env)
。也许会有帮助。
"""
Django settings for my_site project on Heroku. For more info, see:
https://github.com/heroku/heroku-django-template

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/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

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django.contrib.gis',
    'storages',
    'easy_thumbnails',
    'image_cropping',
    'architecture',
    'blog',
]

MIDDLEWARE_CLASSES = [
    '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.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'my_site.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',
            ],
            'debug': DEBUG,
        },
    },
]

WSGI_APPLICATION = 'my_site.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'heroku_my_site',
        'USER': 'postgres',
        'PASSWORD': 'password',
        'HOST': 'localhost',
    }
}

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/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Copenhagen'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, 'static'),
]

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'uploads')
MEDIA_URL = '/media/'

# Amazon S3 configuration
# Add MY_SECRET_KEY, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to your Heroku config vars
if not DEBUG:
    MY_SECRET_KEY = os.environ.get('MY_SECRET_KEY')
    AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
    AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
    AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
    ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

# Easy thumbnails
from easy_thumbnails.conf import Settings as easy_thumbnail_settings
THUMBNAIL_PROCESSORS = (
    'image_cropping.thumbnail_processors.crop_corners',
)
THUMBNAIL_PROCESSORS += easy_thumbnail_settings.THUMBNAIL_PROCESSORS

IMAGE_CROPPING_SIZE_WARNING = True
# size is "width x height"
IMAGE_CROPPING_THUMB_SIZE = (300, 300)
$ pip freeze
appdirs==1.4.0
boto3==1.4.4
botocore==1.5.9
dj-database-url==0.4.2
Django==1.10.5
django-appconf==1.0.1
django-image-cropping==1.0.4
django-storages==1.5.2
docutils==0.13.1
easy-thumbnails==2.4.1
gunicorn==19.6.0
jmespath==0.9.1
olefile==0.44
packaging==16.8
Pillow==4.2.1
psycopg2==2.7.1
pyparsing==2.1.10
python-dateutil==2.6.0
pytz==2017.2
s3transfer==0.1.10
six==1.10.0
whitenoise==3.3.0
$ heroku run python manage.py migrate

Running python manage.py migrate on ⬢ my-site... up, run.8591 (Free)
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 342, in execute
    self.check()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 62, in _run_checks
    issues.extend(super(Command, self)._run_checks(**kwargs))
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 361, in _run_checks
    return checks.run_checks(**kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    for pattern in resolver.url_patterns:
  File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 313, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
    return import_module(self.urlconf_name)
  File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/app/my_site/urls.py", line 23, in <module>
    from architecture.views import mapdata
  File "/app/architecture/views.py", line 24, in <module>
    fields=('point', 'project', 'slug',), stream=out)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/serializers/base.py", line 79, in serialize
    for count, obj in enumerate(queryset, start=1):
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 256, in __iter__
    self._fetch_all()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 1087, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 54, in __iter__
    results = compiler.execute_sql()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 824, in execute_sql
    sql, params = self.as_sql()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 369, in as_sql
    extra_select, order_by, group_by = self.pre_sql_setup()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 46, in pre_sql_setup
    self.setup_query()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 37, in setup_query
    self.select, self.klass_info, self.annotation_col_map = self.get_select()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 226, in get_select
    ret.append((col, self.compile(col, select_format=True), alias))
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 355, in compile
    return node.output_field.select_format(self, sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/gis/db/models/fields.py", line 64, in select_format
    if connection.ops.select:
AttributeError: 'DatabaseOperations' object has no attribute 'select'