gpt4 book ai didi

Python Django migrate_schemas --shared TypeError : hasattr(): attribute name must be string upon

转载 作者:行者123 更新时间:2023-11-28 19:18:27 26 4
gpt4 key购买 nike

我正在尝试使用 django-tenant-schema 创建一个 python django-mako-plus 项目。我完全按照此处教程的说明进行操作:

https://django-tenant-schemas.readthedocs.org/en/latest/install.html#basic-settings

但是,当我运行 cmd: python manage.py migrate_schemas --shared 时,出现以下错误:

File "C:\Python34\lib\site-packages\django\db\utils.py", line 234, in __getitem__
if hasattr(self._connections, alias):
TypeError: hasattr(): attribute name must be string

有哪些可能的问题?

仅供引用,这是我的设置文件:

"""
Django settings for tents_dmp project.

Generated by 'django-admin startproject' using Django 1.8.1.

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 = 'ekr-az&e)g_7&&%um+c%652b72#e035a#_y7rv19jl1qj47t)k'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

SHARED_APPS = (
'tenant_schemas', # mandatory
#'customers', # you must list the app where your tenant model resides in
'homepage',

'django.contrib.contenttypes',

# everything below here is optional
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',

#'django.contrib.staticfiles',
#'django_mako_plus.controller',
)

TENANT_APPS = (
# The following Django contrib apps must be in TENANT_APPS
'django.contrib.contenttypes',

# your tenant-specific apps
)

INSTALLED_APPS = list(set(SHARED_APPS + TENANT_APPS))

TENANT_MODEL = "homepage.Client" # app.Model



MIDDLEWARE_CLASSES = (
'tenant_schemas.middleware.TenantMiddleware',
'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',
'django_mako_plus.controller.router.RequestInitMiddleware',
)

ROOT_URLCONF = 'tents_dmp.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
#'django.core.context_processors.request',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
#...
)
WSGI_APPLICATION = 'tents_dmp.wsgi.application'


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

DATABASES = {
'default': {
'ENGINE': 'tenant_schemas.postgresql_backend',
'NAME': 'database2',
'USER': 'postgres',
'PASSWORD': 'XXX',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}

DATABASE_ROUTERS = (
'tenant_schemas.routers.TenantSyncRouter',
)
# 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_URL = '/static/'

STATICFILES_DIRS = (
# SECURITY WARNING: this next line must be commented out at deployment
BASE_DIR,
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')




DEBUG_PROPAGATE_EXCEPTIONS = DEBUG # never set this True on a live site
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler',
'formatter': 'simple'
},
},
'loggers': {
'django_mako_plus': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
},
}


###############################################################
### Specific settings for the Django-Mako-Plus app

DJANGO_MAKO_PLUS = {
# identifies where the Mako template cache will be stored, relative to each app
'TEMPLATES_CACHE_DIR': 'cached_templates',

# the default app and page to render in Mako when the url is too short
'DEFAULT_PAGE': 'index',
'DEFAULT_APP': 'homepage',

# the default encoding of template files
'DEFAULT_TEMPLATE_ENCODING': 'utf-8',

# these are included in every template by default - if you put your most-used libraries here, you won't have to import them exlicitly in templates
'DEFAULT_TEMPLATE_IMPORTS': [
'import os, os.path, re, json',
],

# see the DMP online tutorial for information about this setting
'URL_START_INDEX': 0,

# whether to send the custom DMP signals -- set to False for a slight speed-up in router processing
# determines whether DMP will send its custom signals during the process
'SIGNALS': True,

# whether to minify using rjsmin, rcssmin during 1) collection of static files, and 2) on the fly as .jsm and .cssm files are rendered
# rjsmin and rcssmin are fast enough that doing it on the fly can be done without slowing requests down
'MINIFY_JS_CSS': True,

# see the DMP online tutorial for information about this setting
'TEMPLATES_DIRS': [
# '/var/somewhere/templates/',
],
}

### End of settings for the Django-Mako-Plus
################################################################

主页应用程序中的 models.py 文件:

from django.db import models
from tenant_schemas.models import TenantMixin

class Client(TenantMixin):
name = models.CharField(max_length=100)
paid_until = models.DateField()
on_trial = models.BooleanField()
created_on = models.DateField(auto_now_add=True)

auto_create_schema = True

任何帮助将不胜感激

C:\Users\Desktop\django\tents_dmp>python manage.py migrate_schemas
--shared
=== Running migrate for schema public
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
338, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\tenant_schemas\management\commands\migrate
_schemas.py", line 24, in run_from_argv
super(MigrateSchemasCommand, self).run_from_argv(argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 390,
in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 441,
in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\tenant_schemas\management\commands\migrate
_schemas.py", line 34, in handle
self.run_migrations(self.schema_name, settings.SHARED_APPS)
File "C:\Python34\lib\site-packages\tenant_schemas\management\commands\migrate
_schemas.py", line 61, in run_migrations
command.execute(*self.args, **defaults)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 441,
in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py
", line 70, in handle
connection = connections[db]
File "C:\Python34\lib\site-packages\django\db\utils.py", line 234, in __getite
m__
if hasattr(self._connections, alias):
TypeError: hasattr(): attribute name must be string

最佳答案

这是你的问题:

https://github.com/bernardopires/django-tenant-schemas/issues/252

DTS 仍然不能与 django 1.8 一起使用,但这里有一个具有更改内容的分支。

https://github.com/tomturner/django-tenant-schemas/commit/fe437f7c81af8484614b3dcdaeb7ad5c43249f54

看起来它适用于 1.7 和 1.8,但我还没有测试过。

由于我开始了一个新项目,我可能会暂时降级 django。

关于Python Django migrate_schemas --shared TypeError : hasattr(): attribute name must be string upon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30469120/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com