如何修复Django中缺失socialaccount_socialapp_sites表的问题?
先确认
settings.py里的配置是否完全到位:django.contrib.sites必须在INSTALLED_APPS列表中- 明确设置
SITE_ID = 1(或者你实际使用的站点ID)
尝试单独重新应用socialaccount的迁移:
有时候全局migrate可能没正确处理某部分,执行命令:python manage.py migrate socialaccount如果上述步骤无效,手动创建表:
根据Django allauth的默认表结构,直接在数据库中执行以下SQL语句(SQLite示例,其他数据库可稍作调整,比如MySQL用AUTO_INCREMENT,PostgreSQL用SERIAL):CREATE TABLE socialaccount_socialapp_sites ( id INTEGER PRIMARY KEY AUTOINCREMENT, socialapp_id INTEGER NOT NULL REFERENCES socialaccount_socialapp(id) ON DELETE CASCADE, site_id INTEGER NOT NULL REFERENCES django_site(id) ON DELETE CASCADE, UNIQUE(socialapp_id, site_id) );极端情况:如果迁移记录异常,可以先备份数据库,然后删除
django_migrations表中所有app为socialaccount的记录,再重新执行:python manage.py makemigrations socialaccount python manage.py migrate socialaccount
内容的提问来源于stack exchange,提问作者amit
相关产品推荐
相关产品推荐

