当我尝试使用social_auth通过OpenID登录时,出现错误: 表'django_db.social_auth_association'不存在。
我必须调用 syncdb ,但它没有为social_auth创建任何表。
为什么 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',
)
答案 0 :(得分:2)
经过一番研究后我找到了一个解决方案。
问题在于我使用的fork。当我从他们那里尝试干净的例子时,我得到了同样的错误,表social_auth_association不存在。
然后我尝试使用original存储库。当我运行 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。
换句话说,我将models.py从fork替换为来自原始存储库的models.py并运行 syncdb 。