简体   繁体   English

带有django错误的python-social-auth“没有这样的表:app_customuser”

[英]python-social-auth with django errors with “no such table: app_customuser”

I'm trying to log-in with twitter using example https://github.com/omab/python-social-auth/tree/master/examples/django_example 我正在尝试使用示例https://github.com/omab/python-social-auth/tree/master/examples/django_example登录Twitter

The twitter side goes fine with twitter redirecting my into http://127.0.0.1:8000/complete/twitter where I'm getting twitter方面很好用twitter将我重定向到http://127.0.0.1:8000/complete/twitter我得到了

OperationalError at /complete/twitter/ no such table: app_customuser OPERError在/ complete / twitter / no这样的表:app_customuser

Environment: 环境:

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

Have no idea what's going on with this one. 不知道这个是怎么回事。

I've managed to make this work by specifying app within makemigrations command. 我已经设法通过在makemigrations命令中指定app来完成这项工作。 Please try: 请试试:

(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

For your new app you need to migrate new models. 对于新app您需要migrate新模型。

Try python manage.py migrate app and then python manage.py makemigrations app 尝试python manage.py migrate app ,然后使用python manage.py makemigrations app

This should work. 这应该工作。

It seems that you created class CustomUser(models.Model) in example/app/models.py and haven't migrated your changes. 您似乎在example/app/models.py创建了class CustomUser(models.Model)并且尚未迁移您的更改。 So if that is so you need to run python manage.py makemigrations and then python manage.py migrate 因此,如果是这样,您需要运行python manage.py makemigrations ,然后运行python manage.py migrate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM