Django: ValueError Table allauth_socialapp 不存在
Django: ValueError Table allauth_socialapp does not exist
我成功地遵循了 this 教程,一切似乎都很好。然后我创建了一个配置文件模型,并设法通过 POST 请求和管理面板创建了它的对象。然后我创建了信号,以便在用户注册后立即创建配置文件。经过反复试验,我终于做到了,并决定刷新数据库。当我尝试这样做并且 运行 python manage.py 刷新时,我得到了这个错误:
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
有人可以帮我解决这个问题吗?我不知道我应该做什么,也无法在网上真正找到答案。
尝试pythonmanage.py makemigrations AppName
如果这不起作用,您可以删除 migration folder
和您的 database
并尝试。
只需将 'allauth.socialaccount'
添加到我的 INSTALLED_APPS
并进行迁移即可解决此问题。现在一切正常。
我成功地遵循了 this 教程,一切似乎都很好。然后我创建了一个配置文件模型,并设法通过 POST 请求和管理面板创建了它的对象。然后我创建了信号,以便在用户注册后立即创建配置文件。经过反复试验,我终于做到了,并决定刷新数据库。当我尝试这样做并且 运行 python manage.py 刷新时,我得到了这个错误:
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
有人可以帮我解决这个问题吗?我不知道我应该做什么,也无法在网上真正找到答案。
尝试pythonmanage.py makemigrations AppName
如果这不起作用,您可以删除 migration folder
和您的 database
并尝试。
只需将 'allauth.socialaccount'
添加到我的 INSTALLED_APPS
并进行迁移即可解决此问题。现在一切正常。