Django:ValueError表allauth_socialapp不存在

时间:2019-08-25 17:36:50

标签: python django rest allauth

我成功地遵循了https://tools.ietf.org/html/rfc8017#section-4.1教程,一切似乎都还不错。然后,我创建了一个Profile模型,并通过POST请求和管理面板设法创建了它的对象。然后,我创建了信号,以便可以在用户注册后立即创建配置文件。经过一番尝试和错误之后,我终于做到了,并决定将数据库刷新。当我尝试这样做并运行python manage.py flush时,出现此错误:

raise ValueError("Table %s does not exist" % table_name)
ValueError: Table allauth_socialapp does not exist


Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\commands\flush.py", line 49, in handle
    allow_cascade=allow_cascade)
  File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\sql.py", line 16, in sql_flush
    seqs = connection.introspection.sequence_list() if reset_sequences else ()
  File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\db\backends\base\introspection.py", line 118, in sequence_list
    sequence_list.extend(self.get_sequences(cursor, model._meta.db_table, model._meta.local_fields))
  File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\db\backends\sqlite3\introspection.py", line 96, in get_sequences
    pk_col = self.get_primary_key_column(cursor, table_name)
  File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\db\backends\sqlite3\introspection.py", line 196, in get_primary_key_column
    raise ValueError("Table %s does not exist" % table_name)
ValueError: Table allauth_socialapp does not exist

我已经尝试为每个已安装的应用执行python manage.py迁移,但是似乎没有任何效果,并且已经尝试删除Profile模型及其正在使用的接收器,但这不能解决问题。还尝试删除sqlite文件和所有迁移,但没有帮助。

我的 models.py 文件如下所示:

class Profile(models.Model):
GENDER_CHOICES = (
    ('Male', 'Male'),
    ('Female', 'Female')
)

user = models.OneToOneField(User, on_delete=models.CASCADE, null=True)
interests = models.CharField(max_length=100, null=True)
gender = models.CharField(max_length=6, choices=GENDER_CHOICES, null=True)

def __str__(self):
    return f"{self.user}'s Profile"


@receiver(user_signed_up)
def user_registered(sender, request, user, **kwargs):
    print(f"Created profile for {   user}")
    Profile.objects.create(user=user)
    """Creates the Profile after user registers"""

和我的 settings.py 文件:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'rest_auth.registration',
    'core'
]


REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
    ],
}

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
SITE_ID = 1

有人可以帮我吗?我不知道该怎么办,也无法在线真正找到答案。

2 个答案:

答案 0 :(得分:0)

尝试使用python SELECT ROW_NUMBER() OVER(PARTITION BY countryname ORDER BY eventid,countryname,place asc) AS Row,* FROM competitormainviewpoints2021isrc ORDER BY row,eventid,place ASC

如果此操作无效,则可以删除manage.py makemigrations AppNamemigration folder并尝试。

答案 1 :(得分:0)

通过将'allauth.socialaccount'添加到我的INSTALLED_APPS并进行迁移来解决此问题。现在一切正常。