You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Django中缺失socialaccount_socialapp_sites表的问题?

解决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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 11:42:04