cc-switch import / cloud sync failures: foreign keys, read-only database, overwrites
Quick fix
Upgrade cc-switch and avoid syncing provider_health or a read-only db; after picking a file, click 导入 (Import) rather than 保存 (Save).
Symptom
Section titled “Symptom”下载失败:数据库错误: 恢复表 provider_health 数据失败: FOREIGN KEY constraint failedDownload failed: database error: failed to restore data for table provider_health: FOREIGN KEY constraint failed
This cluster covers several kinds of import and sync problem. The most common one: restoring a WebDAV download also syncs the provider_health table, and that table has a foreign key pointing at providers. If one machine deleted a provider while another machine still holds the matching provider_health rows locally, restoring the snapshot trips FOREIGN KEY constraint failed. A maintainer confirmed provider_health should not take part in sync, and fixed it. Other variants: cc-switch.db turns read-only after being synced by a cloud drive, giving attempt to write a readonly database; after importing a config you have to click 导入 (Import) on the left again rather than only 保存 (Save); syncing an old-style config directory lets the last active provider overwrite other machines; and audit-level problems in 3.19.1 where the profiles table did not trigger WebDAV/S3 auto-sync and SQL backup/restore could lose the AUTOINCREMENT high-water mark.
Upgrade cc-switch on both ends to a version that includes the fix. A maintainer confirmed the provider_health-in-sync problem is fixed and ships with newer releases.
If you sync over WebDAV or a cloud drive, sync only cc-switch.db, not the whole old config directory. Newer versions use a layered storage architecture and only the database file needs syncing.
If you get attempt to write a readonly database, check the permissions on cc-switch.db in the sync directory, make it read-write, and restart cc-switch.
cc-switch.db(位于你设置的云同步文件夹内) # 将文件权限从只读改为读写When importing JSON or a backup by hand, pick the file and then click the 导入 (Import) button on the left, not just 保存 (Save) below. Users have confirmed the import succeeds that way.
If the cloud copy has already been upgraded to db-v6 and the old data will not restore, install the older cc-switch first to sync the data back, then upgrade again.
On a WebDAV 401, check the server path, credentials, and permissions. Some users mention having to disable the 1024 path check.
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 25 real issues
- #140配置导入有问题
- #141codex通用配置
- #167备份优化
- #230期望支持json格式的mcp导入
- #287配置目录同步问题
- #303skill无法识别
- #353本地的cc mcp配置和cc-switch中的mcp配置不同步
- #361升级3.8.2版本后无法更新供应商和切换供应商
- #631增加webdav同步功能
- #801导入配置失效
- #954使用中时候总开关应同步
- #1141每次导入的时候 接管模式都会变
- #1388WebDAV从云端下载同步失败,提示【数据库错误: 恢复表 provider_health 数据失败: FOREIGN KEY constraint failed】
- #1488webdev 云同步自动上传,增加落后版本提示
- #1576开启云端同步的情况下,云端数据变为db-v6了,旧数据没法恢复,这怎么搞?
- #1646多端同步数据异常
- #1703WebDAV 拉取远端备份报错 SHA256校验失败
- #1711【bug】多设备云同步配置失败
- #1715没有相应模型配置时,点击【导入当前配置】弹出的错误提示文案为空
- #2883Optimization: Refactor session usage sync to reduce CPU/IO spikes
- #6132[Bug] Profile changes do not trigger WebDAV or S3 auto-sync
- #6134[Bug] SQL import resets incremental auto-vacuum mode
- #6135[Bug] SQL dumps do not preserve all SQLite scalar values
- #6136[Bug] SQL backup restore loses AUTOINCREMENT high-water marks
- #6139[Bug] Sync apply can overwrite local writes made during staging
- Both machines are on the latest version — why does the WebDAV download still report FOREIGN KEY constraint failed?
- Because one machine deleted a provider while the other still holds the matching provider_health rows locally. Restoring the cloud snapshot finds no matching providers row and the foreign key fails. A maintainer has confirmed provider_health should not take part in sync.
- I imported a config file and nothing changed. Why?
- After picking the file you have to click the 导入 (Import) button on the left again, not just 保存 (Save) below. Users have confirmed that works.
- Why do I get attempt to write a readonly database after syncing with a cloud drive?
- cc-switch.db in the sync folder may have turned read-only. Find that database file, make it read-write, and restart cc-switch.
- Can I still restore the old data after the cloud copy became db-v6?
- Yes. Install the older cc-switch first, sync the cloud data back, then upgrade to the new version.
- WebDAV returns 401. What now?
- Check the WebDAV account, password, path, and permissions. Some users mention that certain servers need the 1024 path check disabled.
- Does MCP configuration sync automatically?
- In the early design, MCP data was imported once on first run only when the app had none. MCP installed later by other means does not sync automatically. A maintainer mentioned a manual sync button is planned for a future version.
Related problems
Section titled “Related problems”This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.