/ oauth / complete / google-oauth2 /处的ProgrammingError(1146,“表'emunshi.social_auth_usersocialauth'不存在”)

时间:2018-06-22 08:16:37

标签: python-2.7 django-1.11

无法添加Google身份验证。表不存在,应用迁移无济于事。没有表被创建。请帮我拿桌子。

Settings.py

import os

from decouple import config
env = os.environ.copy()

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

ALLOWED_HOSTS = ["myemunshi.com","myemunshi.com:8000","vakildesk.com","ec2-35-154-74-43.ap-south-1.compute.amazonaws.com","35.154.74.43", 'localhost', '127.0.0.1']

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.staticfiles',
    'django.contrib.messages',
    'storages',
    'core',
    'rest_framework',
    'rest_framework.authtoken',
    #'django_celery_beat',
    'social_django',
    'social-auth-app-django',
    # 'allauth',
    # 'allauth.account',
    # 'rest_auth.registration',
    'corsheaders',
    'rest_auth',
]

SECRET_KEY = config('SECRET_KEY')

ACCOUNT_LOGOUT_ON_GET = True

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'corsheaders.middleware.CorsMiddleware',

   'django.middleware.common.CommonMiddleware',

   #'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   #'debug_toolbar.middleware.DebugToolbarMiddleware',
   'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware',
   'social_django.middleware.SocialAuthExceptionMiddleware',
]
#INTERNAL_IPS = '127.0.0.1'

ROOT_URLCONF = 'django_login.urls'

LOGIN_REDIRECT_URL = '/index/'
LOGIN_URL = '/login'
# AUTH_USER_MODEL = 'core.User'

#Database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': config('DB_NAME'),
        'USER': config('DB_USER'),
        'PASSWORD': config('DB_PASSWORD'),
        'HOST': config('DB_HOST'),   # Or an IP Address that your DB is hosted on
        'PORT': config('DB_PORT'),
    }
}


"""

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': config("DB_NAME"),
        'USER': 'root',
        'PASSWORD': '',
        'HOST': config('DB_HOST'),
        'PORT': config('DB_PORT'),
    }
}
"""

AUTHENTICATION_BACKENDS = (
    'social_core.backends.facebook.FacebookOAuth2',
    'social_core.backends.google.GoogleOAuth2',
    'core.backends.EmailBackend',

    'social_core.backends.open_id.OpenIdAuth',  # for Google authentication
    'social_core.backends.google.GoogleOpenId',  # for Google authentication
    'social_core.backends.google.GoogleOAuth2',  # for Google authentication
    'social_core.backends.facebook.FacebookOAuth2',  # for Facebook authentication

    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.auth_allowed',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'core.pipeline.check_email_exists',
    'social_core.pipeline.social_auth.associate_by_email',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',

)

SOCIAL_AUTH_LOGIN_ERROR_URL = '/login'
SOCIAL_AUTH_REDIRECT_IS_HTTPS = True


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]


# Fb Oauth
SOCIAL_AUTH_FACEBOOK_KEY = '1633135106725473'
SOCIAL_AUTH_FACEBOOK_SECRET = '73b68b735181ddf162ba1ff5e59f3d67'
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_CREATE_USERS = True
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
 'fields': 'id, name, email, age_range'
}
SOCIAL_AUTH_FACEBOOK_API_VERSION = '2.10'

# G+ Oauth
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '11747636078-ets1rtb1kg29fk1k2fe1rra75ftu9bu1.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'Vsv3caArc7w8uTRM2UPHY_uN'
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = ['email']

SOCIAL_AUTH_REDIRECT_IS_HTTPS = False

# Twitter Oauth
# SOCIAL_AUTH_TWITTER_KEY = 'WVu9iz02cGm4xi5pSEP5l3AlA'
# SOCIAL_AUTH_TWITTER_SECRET = '6PaRafQ6JnkDQOJeUm3CuJys7DhwYqJeER8KMW3e1Jq0WBprqy'

# Github Oauth
# SOCIAL_AUTH_GITHUB_KEY = '8c41c9c5e7f40d4e70e7'
# SOCIAL_AUTH_GITHUB_SECRET = '33bba9e4094617f72fbf08585062b086342cb480'

# REST_FRAMEWORK = {
#     # 'DEFAULT_PERMISSION_CLASSES': (
#     #     'rest_framework.permissions.IsAuthenticated',
#     # ),
# 'DEFAULT_AUTHENTICATION_CLASSES': (
#        'rest_framework.authentication.BasicAuthentication',
#         'rest_framework.authentication.SessionAuthentication',
#     )
# }
# REST_FRAMEWORK = {
#     'DEFAULT_AUTHENTICATION_CLASSES': (
#         'rest_framework.authentication.TokenAuthentication',
#     ),
#     'DEFAULT_PERMISSION_CLASSES': (
#         'rest_framework.permissions.IsAuthenticated',
#     )
# }
WSGI_APPLICATION = 'django_login.wsgi.application'


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE =  'Asia/Kolkata'

USE_I18N = True

USE_L10N = True

USE_TZ = True


STATIC_URL = '/static/'

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles/')
#print 'static_root is '+STATIC_ROOT


STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    #os.path.join(PROJECT_ROOT, 'static'),
]
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django_assets.finders.AssetsFinder',
    # other finders..
    #'compressor.finders.CompressorFinder',
)


# Email Configurations

DEFAULT_EMAIL_FROM = 'vakildesk@noreply.com'
DEFAULT_EMAIL_BCC = 'vakildesk@noreply.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST =  'smtp.gmail.com'
EMAIL_PORT =  587
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

CORS_ALLOW_METHODS = (
    'DELETE',
    'GET',
    'OPTIONS',
    'PATCH',
    'POST',
    'PUT',
)
#CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
# CORS_ALLOW_CREDENTIALS = True
#
# CORS_ALLOW_HEADERS = (
#     'accept',
#     'accept-encoding',
#     'authorization',
#     'content-type',
#     'dnt',
#     'origin',
#     'user-agent',
#     'x-csrftoken',
#     'x-requested-with',
# )
FIREBASE_URL = '/firebase'
FIREBASE_ROOT = os.path.join(BASE_DIR, 'firebase')

MESSAGE_LEVEL = 10  # DEBUG

from django.contrib.messages import constants as messages

MESSAGE_TAGS = {
    messages.DEBUG: 'alert-info',
    messages.INFO: 'alert-info',
    messages.SUCCESS: 'alert-success',
    messages.WARNING: 'alert-warning',
    messages.ERROR: 'alert-danger',
}

我正在将oauth2与Google的api一起使用。请在已安装的应用程序中查看social-django。如果有人能解释一下表格的形成方式,那就太好了,所以也许我可以再试一次。

0 个答案:

没有答案