質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

OAuth 2.0

OAuth 2.0(Open Authorization 2.0)は、APIを通して保護されたリソース(サードパーティのアプリケーション)へアクセスする為のオープンプロトコルです。

Q&A

解決済

1回答

3329閲覧

no such table: social_auth_usersocialauthのエラー

shirasu10fish

総合スコア35

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

OAuth 2.0

OAuth 2.0(Open Authorization 2.0)は、APIを通して保護されたリソース(サードパーティのアプリケーション)へアクセスする為のオープンプロトコルです。

0グッド

1クリップ

投稿2018/02/25 12:39

編集2018/02/25 12:43

前提・実現したいこと

Djangoでpython-social-authを用いてGoogle認証を実装しようとしています。
index.htmlの「Login with Google」ボタンからGoogleのログイン画面に飛び、その後のリダイレクトで次のエラーメッセージが発生しました。

エラーメッセージ(概要)

OperationalError at /complete/google-oauth2/
no such table: social_auth_usersocialauth

エラーメッセージ(詳細)

Environment: Request Method: GET Request URL: http://localhost:8000/complete/google-oauth2/?state=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Django Version: 2.0.2 Python Version: 3.5.2 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'social.apps.django_app.default', 'auth0', 'auth1'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] Traceback: File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute 85. return self.cursor.execute(sql, params) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py" in execute 303. return Database.Cursor.execute(self, query, params) The above exception (no such table: social_auth_usersocialauth) was the direct cause of the following exception: File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner 35. response = get_response(request) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response 128. response = self.process_exception_by_middleware(e, request) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response 126. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/views/decorators/csrf.py" in wrapped_view 54. return view_func(*args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_django/utils.py" in wrapper 49. return func(request, backend, *args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_django/views.py" in complete 33. *args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/actions.py" in do_complete 41. user = backend.complete(user=user, *args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/backends/base.py" in complete 40. return self.auth_complete(*args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/utils.py" in wrapper 252. return func(*args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/backends/oauth.py" in auth_complete 405. *args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/utils.py" in wrapper 252. return func(*args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/backends/oauth.py" in do_auth 416. return self.strategy.authenticate(*args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_django/strategy.py" in authenticate 107. return authenticate(*args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/contrib/auth/__init__.py" in authenticate 70. user = _authenticate_with_backend(backend, backend_path, request, credentials) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/contrib/auth/__init__.py" in _authenticate_with_backend 116. return backend.authenticate(*args, **credentials) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/backends/base.py" in authenticate 80. return self.pipeline(pipeline, *args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/backends/base.py" in pipeline 83. out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/backends/base.py" in run_pipeline 113. result = func(*args, **out) or {} File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_core/pipeline/social_auth.py" in social_user 19. social = backend.strategy.storage.user.get_social_auth(provider, uid) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/social_django/models.py" in get_social_auth 51. uid=uid) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/models/query.py" in get 397. num = len(clone) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/models/query.py" in __len__ 254. self._fetch_all() File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/models/query.py" in _fetch_all 1179. self._result_cache = list(self._iterable_class(self)) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/models/query.py" in __iter__ 53. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in execute_sql 1064. cursor.execute(sql, params) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/backends/utils.py" in execute 100. return super().execute(sql, params) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/backends/utils.py" in execute 68. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute_with_wrappers 77. return executor(sql, params, many, context) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute 85. return self.cursor.execute(sql, params) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/utils.py" in __exit__ 89. raise dj_exc_value.with_traceback(traceback) from exc_value File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute 85. return self.cursor.execute(sql, params) File "/home/kei/.virtualenvs/nextone/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py" in execute 303. return Database.Cursor.execute(self, query, params) Exception Type: OperationalError at /complete/google-oauth2/ Exception Value: no such table: social_auth_usersocialauth

nextone/setting.py(抜粋)

python

1INSTALLED_APPS = [ 2 'django.contrib.admin', 3 'django.contrib.auth', 4 'django.contrib.contenttypes', 5 'django.contrib.sessions', 6 'django.contrib.messages', 7 'django.contrib.staticfiles', 8 'social.apps.django_app.default', 9 'auth1', #アプリ名 10] 11 12TEMPLATES = [ 13 { 14 'BACKEND': 'django.template.backends.django.DjangoTemplates', 15 'DIRS': [], 16 'APP_DIRS': True, 17 'OPTIONS': { 18 'context_processors': [ 19 'django.template.context_processors.debug', 20 'django.template.context_processors.request', 21 'django.contrib.auth.context_processors.auth', 22 'django.contrib.messages.context_processors.messages', 23 ], 24 }, 25 }, 26 27 28AUTHENTICATION_BACKENDS = ( 29 'social_core.backends.google.GoogleOAuth2' , 30 'django.contrib.auth.backends.ModelBackend', 31 ) 32 33SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' 34SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'XXXXXXXXXXXXXXXXX' 35 36SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/' 37SOCIAL_AUTH_LOGIN_URL = '/login/'

auth1/templates/auth1/index.html

html

1{% extends "auth1/base.html" %} 2 3{% block title %}ホーム{% endblock title %} 4 5{% block content %} 6<div> 7 <h1>ホーム</h1> 8 9 <p> 10 <ul> 11 {% if user and not user.is_anonymous %} 12 <!-- TODO: ログアウト URL を表示する --> 13 {% else %} 14 <li> 15 <a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.path }}">Login with Google</a> 16 </li> 17 {% endif %} 18 </ul> 19 </p> 20</div> 21{% endblock content %}

###auth1/templates/auth1/base.html

html

1{% load staticfiles %} 2<!DOCTYPE html> 3<html lang="{{ LANGUAGE_CODE|default:"en-us" }}"> 4<head> 5 <meta charset="UTF-8"> 6 <title>{% block title %}{% endblock %}</title> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 {% block extrahead %}{% endblock %} 9</head> 10<body> 11 <div class="container"> 12 {% block content %} 13 {{ content }} 14 {% endblock %} 15 </div> 16</body> 17</html>

環境について

python3.5.2
pip9.0.1
ubuntu16.04 x84_64

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Exception Type: OperationalError at /complete/google-oauth2/ Exception Value: no such table: social_auth_usersocialauth

これは social-authが必要とするテーブルが存在しないというエラーです。social-auth を Djangoで使う時は、
migrateが必要になります。

あとお使いのバージョンが多分古いです。下記URLが参考になると思います。

https://qiita.com/sapuri/items/70418a8bc45ab21de960

投稿2018/03/12 17:52

tell_k

総合スコア2120

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

shirasu10fish

2018/03/16 23:29

URL先の通りにアップデートをしてからmigrateを実施したところ、上手く行きました。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問