python-social-auth 与 django 错误 "no such table: app_customuser"
python-social-auth with django errors with "no such table: app_customuser"
我正在尝试使用示例登录 Twitter https://github.com/omab/python-social-auth/tree/master/examples/django_example
推特方面一切顺利,推特将我重定向到 http://127.0.0.1:8000/complete/twitter
我要去哪里
/complete/twitter/ 操作错误
没有这样的 table: app_customuser
环境:
Request Method: GET
Request URL: http://127.0.0.1:8000/complete/twitter/?redirect_state=BLa0NTd6yUIEa47Aa0GimQJs8DK7iFg3&oauth_token=vj8STgAAAAAAkXlhAAABUuA6ldA&oauth_verifier=gUDxqTwS20PRPUlgDEQ3QN7T237qUdAR
Django Version: 1.9.2
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'social.apps.django_app.default',
'example.app')
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 "/home/bob/.local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/bob/.local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/bob/.local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/home/bob/.local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "../../social/apps/django_app/utils.py" in wrapper
51. return func(request, backend, *args, **kwargs)
File "../../social/apps/django_app/views.py" in complete
28. redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs)
File "../../social/actions.py" in do_complete
43. user = backend.complete(user=user, *args, **kwargs)
File "../../social/backends/base.py" in complete
41. return self.auth_complete(*args, **kwargs)
File "../../social/utils.py" in wrapper
229. return func(*args, **kwargs)
File "../../social/backends/oauth.py" in auth_complete
182. return self.do_auth(access_token, *args, **kwargs)
File "../../social/utils.py" in wrapper
229. return func(*args, **kwargs)
File "../../social/backends/oauth.py" in do_auth
193. return self.strategy.authenticate(*args, **kwargs)
File "../../social/strategies/django_strategy.py" in authenticate
96. return authenticate(*args, **kwargs)
File "/home/bob/.local/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in authenticate
74. user = backend.authenticate(**credentials)
File "../../social/backends/base.py" in authenticate
82. return self.pipeline(pipeline, *args, **kwargs)
File "../../social/backends/base.py" in pipeline
85. out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
File "../../social/backends/base.py" in run_pipeline
112. result = func(*args, **out) or {}
File "../../social/pipeline/social_auth.py" in social_user
20. social = backend.strategy.storage.user.get_social_auth(provider, uid)
File "../../social/apps/django_app/default/models.py" in get_social_auth
48. uid=uid)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/query.py" in get
381. num = len(clone)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
240. self._fetch_all()
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
1074. self._result_cache = list(self.iterator())
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/query.py" in __iter__
52. results = compiler.execute_sql()
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
848. cursor.execute(sql, params)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
79. return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/utils.py" in __exit__
95. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
323. return Database.Cursor.execute(self, query, params)
Exception Type: OperationalError at /complete/twitter/
Exception Value: no such table: app_customuser
不知道这个是怎么回事。
您似乎在 example/app/models.py
中创建了 class CustomUser(models.Model)
,但尚未迁移您的更改。
因此,如果是这样,您需要 运行 python manage.py makemigrations
然后 python manage.py migrate
我通过在 makemigrations
命令中指定 app
成功地完成了这项工作。请尝试:
(env)$ python manage.py makemigrations app
Migrations for 'app':
0001_initial.py:
- Create model CustomUser
(env)$ python manage.py migrate
Operations to perform:
Apply all migrations: app, admin, sites, default, sessions, auth, contenttypes
Running migrations:
Rendering model states... DONE
Applying app.0001_initial... OK
对于新 app
,您需要 migrate
新模型。
尝试 python manage.py migrate app
然后 python manage.py makemigrations app
这应该有效。
我正在尝试使用示例登录 Twitter https://github.com/omab/python-social-auth/tree/master/examples/django_example
推特方面一切顺利,推特将我重定向到 http://127.0.0.1:8000/complete/twitter 我要去哪里
/complete/twitter/ 操作错误 没有这样的 table: app_customuser
环境:
Request Method: GET
Request URL: http://127.0.0.1:8000/complete/twitter/?redirect_state=BLa0NTd6yUIEa47Aa0GimQJs8DK7iFg3&oauth_token=vj8STgAAAAAAkXlhAAABUuA6ldA&oauth_verifier=gUDxqTwS20PRPUlgDEQ3QN7T237qUdAR
Django Version: 1.9.2
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'social.apps.django_app.default',
'example.app')
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 "/home/bob/.local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/bob/.local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/bob/.local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/home/bob/.local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "../../social/apps/django_app/utils.py" in wrapper
51. return func(request, backend, *args, **kwargs)
File "../../social/apps/django_app/views.py" in complete
28. redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs)
File "../../social/actions.py" in do_complete
43. user = backend.complete(user=user, *args, **kwargs)
File "../../social/backends/base.py" in complete
41. return self.auth_complete(*args, **kwargs)
File "../../social/utils.py" in wrapper
229. return func(*args, **kwargs)
File "../../social/backends/oauth.py" in auth_complete
182. return self.do_auth(access_token, *args, **kwargs)
File "../../social/utils.py" in wrapper
229. return func(*args, **kwargs)
File "../../social/backends/oauth.py" in do_auth
193. return self.strategy.authenticate(*args, **kwargs)
File "../../social/strategies/django_strategy.py" in authenticate
96. return authenticate(*args, **kwargs)
File "/home/bob/.local/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in authenticate
74. user = backend.authenticate(**credentials)
File "../../social/backends/base.py" in authenticate
82. return self.pipeline(pipeline, *args, **kwargs)
File "../../social/backends/base.py" in pipeline
85. out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
File "../../social/backends/base.py" in run_pipeline
112. result = func(*args, **out) or {}
File "../../social/pipeline/social_auth.py" in social_user
20. social = backend.strategy.storage.user.get_social_auth(provider, uid)
File "../../social/apps/django_app/default/models.py" in get_social_auth
48. uid=uid)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/query.py" in get
381. num = len(clone)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
240. self._fetch_all()
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
1074. self._result_cache = list(self.iterator())
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/query.py" in __iter__
52. results = compiler.execute_sql()
File "/home/bob/.local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
848. cursor.execute(sql, params)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
79. return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/utils.py" in __exit__
95. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/home/bob/.local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
323. return Database.Cursor.execute(self, query, params)
Exception Type: OperationalError at /complete/twitter/
Exception Value: no such table: app_customuser
不知道这个是怎么回事。
您似乎在 example/app/models.py
中创建了 class CustomUser(models.Model)
,但尚未迁移您的更改。
因此,如果是这样,您需要 运行 python manage.py makemigrations
然后 python manage.py migrate
我通过在 makemigrations
命令中指定 app
成功地完成了这项工作。请尝试:
(env)$ python manage.py makemigrations app
Migrations for 'app':
0001_initial.py:
- Create model CustomUser
(env)$ python manage.py migrate
Operations to perform:
Apply all migrations: app, admin, sites, default, sessions, auth, contenttypes
Running migrations:
Rendering model states... DONE
Applying app.0001_initial... OK
对于新 app
,您需要 migrate
新模型。
尝试 python manage.py migrate app
然后 python manage.py makemigrations app
这应该有效。