Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 表社会认证协会不';不存在_Django_Django Models_Django Socialauth - Fatal编程技术网

Django 表社会认证协会不';不存在

Django 表社会认证协会不';不存在,django,django-models,django-socialauth,Django,Django Models,Django Socialauth,当我尝试使用OpenID登录时,出现一个错误: 表'django_db.social_auth_association'不存在 我不得不调用syncdb,但它没有为社交身份验证创建任何表 为什么syncdb不使用social_auth的模型 这是我的日志: Environment: Request Method: GET Request URL: http://localhost:8000/login/yandex/ Django Version: 1.4 Python Version:

当我尝试使用OpenID登录时,出现一个错误: 表'django_db.social_auth_association'不存在

我不得不调用syncdb,但它没有为社交身份验证创建任何表

为什么syncdb不使用social_auth的模型

这是我的日志:

Environment:


Request Method: GET
Request URL: http://localhost:8000/login/yandex/

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_ipgeobase',
 'myproject.main',
 'social_auth',
 'openid')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File ".../django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File ".../myproject/social_auth/decorators.py" in wrapper
  37.                 return func(request, backend, *args, **kwargs)
File ".../myproject/social_auth/views.py" in auth
  27.     return auth_process(request, backend)
File ".../myproject/social_auth/views.py" in auth_process
  85.     if backend.uses_redirect:
File ".../myproject/social_auth/backends/__init__.py" in uses_redirect
  504.         return self.openid_request().shouldSendRedirect()
File ".../myproject/social_auth/backends/__init__.py" in openid_request
  510.                                                             extra_params))
File ".../myproject/openid/consumer/consumer.py" in begin
  353.             return self.beginWithoutDiscovery(service, anonymous)
File ".../myproject/openid/consumer/consumer.py" in beginWithoutDiscovery
  376.         auth_req = self.consumer.begin(service)
File ".../myproject/openid/consumer/consumer.py" in begin
  598.             assoc = self._getAssociation(service_endpoint)
File ".../myproject/openid/consumer/consumer.py" in _getAssociation
  1158.         assoc = self.store.getAssociation(endpoint.server_url)
File ".../myproject/social_auth/store.py" in getAssociation
  24.                                                                handle)
File ".../myproject/social_auth/db/base.py" in get_oid_associations
  135.                 for assoc in Association.objects.filter(**args)
File ".../django/db/models/query.py" in _result_iter
  118.                 self._fill_cache()
File ".../django/db/models/query.py" in _fill_cache
  875.                     self._result_cache.append(self._iter.next())
File ".../django/db/models/query.py" in iterator
  291.         for row in compiler.results_iter():
File ".../django/db/models/sql/compiler.py" in results_iter
  763.         for rows in self.execute_sql(MULTI):
File ".../django/db/models/sql/compiler.py" in execute_sql
  818.         cursor.execute(sql, params)
File ".../django/db/backends/util.py" in execute
  40.             return self.cursor.execute(sql, params)
File ".../django/db/backends/mysql/base.py" in execute
  114.             return self.cursor.execute(query, args)
File ".../MySQLdb/cursors.py" in execute
  174.             self.errorhandler(self, exc, value)
File ".../MySQLdb/connections.py" in defaulterrorhandler
  36.     raise errorclass, errorvalue

Exception Type: DatabaseError at /login/yandex/
Exception Value: (1146, "Table 'django_db.social_auth_association' doesn't exist")
这是我的settings.py:

import os

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'django_db',                      # Or path to database file if using sqlite3.
        'USER': 'root',                      # Not used with sqlite3.
        'PASSWORD': '1',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

DEFAULT_CHARSET = 'utf-8'

TIME_ZONE = 'Europe/Moscow'

LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True
USE_L10N = True

USE_TZ = True

MEDIA_ROOT = os.path.join(os.path.dirname(__file__), "media") 
MEDIA_URL = '/media/' 

STATIC_ROOT = ''
STATIC_URL = '/static/'

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.contrib.messages.context_processors.messages',
    'social_auth.context_processors.social_auth_by_type_backends',
)

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',
)

ROOT_URLCONF = 'myproject.urls'

WSGI_APPLICATION = 'myproject.wsgi.application'

TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_ipgeobase',
    'myproject.main',
    'social_auth',
    'openid',
)

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.contrib.vkontakte.VKontakteBackend',
    'social_auth.backends.OpenIDBackend',
    'social_auth.backends.google.GoogleBackend',
    'social_auth.backends.contrib.yandex.YandexBackend',
    'django.contrib.auth.backends.ModelBackend',
)

LOGIN_URL          = '/login-form/'
LOGIN_REDIRECT_URL = '/logged-in/'
LOGIN_ERROR_URL    = '/login-error/'

SOCIAL_AUTH_USER_MODEL = 'main.CustomUser'

SOCIAL_AUTH_PIPELINE = (
    'social_auth.backends.pipeline.social.social_auth_user',
    'social_auth.backends.pipeline.associate.associate_by_email',
    'social_auth.backends.pipeline.misc.save_status_to_session',
    'main.pipeline.redirect_to_form',
    'main.pipeline.username',
    'social_auth.backends.pipeline.user.create_user',
    'social_auth.backends.pipeline.social.associate_user',
    'social_auth.backends.pipeline.social.load_extra_data',
    'social_auth.backends.pipeline.user.update_user_details',
    'social_auth.backends.pipeline.misc.save_status_to_session',
    'main.pipeline.redirect_to_form2',
    'main.pipeline.first_name',
)

经过一番研究,我找到了一个解决办法

问题是,我用了。当我尝试从他们那里得到一个干净的例子时,我得到了相同的错误,即表social_auth_关联不存在

然后我尝试使用存储库。当我运行syncdb时,我得到:

Creating table social_auth_usersocialauth
Creating table social_auth_nonce
Creating table social_auth_association
于是,出现了所需的表。之后,我比较了存储库中的源代码并找到了行,这会影响模型的搜索:

import types
..
globals().update((name, value) for name, value in
    ((name, getattr(SOCIAL_AUTH_MODELS_MODULE, name))
        for name in dir(SOCIAL_AUTH_MODELS_MODULE))
            if isinstance(value, (type, types.ClassType)))
而不是

globals().update((name, getattr(SOCIAL_AUTH_MODELS_MODULE, name))
    for name in dir(SOCIAL_AUTH_MODELS_MODULE))
在social_auth/models.py中


换句话说,我从fork将models.py替换为原始存储库中的models.py,并运行了syncdb

请使您的日志可读。可能您应该在settings.py中设置其他变量,例如:AUTHENTICATION\u BACKENDS=('social_auth.backends.facebook.FacebookBackend'、'django.contrib.auth.backends.ModelBackend'…sergzach,我在AUTHENTICATION_backends块中设置了social_auth.backends.OpenIDBackend。我想,这就是我通过OpenID进行日志记录所需要的。好的,让我们开始吧。尝试一下。/manage.py验证。一切正常吗?我从github运行了一个干净的示例,得到了相同的错误。我很高兴。)I’我会试着问问作者。