簡體   English   中英

帶有django錯誤的python-social-auth“沒有這樣的表:app_customuser”

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

我正在嘗試使用示例https://github.com/omab/python-social-auth/tree/master/examples/django_example登錄Twitter

twitter方面很好用twitter將我重定向到http://127.0.0.1:8000/complete/twitter我得到了

OPERError在/ complete / twitter / no這樣的表: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

不知道這個是怎么回事。

我已經設法通過在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

這應該工作。

您似乎在example/app/models.py創建了class CustomUser(models.Model)並且尚未遷移您的更改。 因此,如果是這樣,您需要運行python manage.py makemigrations ,然后運行python manage.py migrate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM