ComfyUI报错SQLite

Context impl SQLiteImpl.
Will assume non-transactional DDL.
Context impl SQLiteImpl.
Will assume non-transactional DDL.
Error upgrading database:
Traceback (most recent call last):
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\base.py", line 213, in _catch_revision_errors
    yield
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\base.py", line 421, in _upgrade_revs
    for script in reversed(list(revs))
                           ^^^^^^^^^^
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\revision.py", line 814, in iterate_revisions
    revisions, heads = fn(
                       ^^^
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\revision.py", line 1475, in _collect_upgrade_revisions
    current_revisions = self.get_revisions(lower)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\revision.py", line 542, in get_revisions
    return sum([self.get_revisions(id_elem) for id_elem in id_], ())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\revision.py", line 542, in <listcomp>
    return sum([self.get_revisions(id_elem) for id_elem in id_], ())
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\revision.py", line 565, in get_revisions
    return tuple(
           ^^^^^^
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\revision.py", line 566, in <genexpr>
    self._revision_for_ident(rev_id, branch_label)
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\revision.py", line 637, in _revision_for_ident
    raise ResolutionError(
alembic.script.revision.ResolutionError: No such revision or branch '0002_merge_to_asset_references'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\ComfyUI\app\database\db.py", line 97, in init_db
    command.upgrade(config, target_rev)
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\command.py", line 483, in upgrade
    script.run_env()
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\base.py", line 545, in run_env
    util.load_python_file(self.dir, "env.py")
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\util\pyfiles.py", line 116, in load_python_file
    module = load_module_py(module_id, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\util\pyfiles.py", line 136, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "D:\ComfyUI\alembic_db\env.py", line 64, in <module>
    run_migrations_online()
  File "D:\ComfyUI\alembic_db\env.py", line 58, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\runtime\environment.py", line 969, in run_migrations
    self.get_context().run_migrations(**kw)
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\runtime\migration.py", line 614, in run_migrations
    for step in self._migrations_fn(heads, self):
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\command.py", line 472, in upgrade
    return script._upgrade_revs(revision, rev)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\base.py", line 409, in _upgrade_revs
    with self._catch_revision_errors(
  File "D:\ComfyUI\.ext\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "D:\ComfyUI\.ext\Lib\site-packages\alembic\script\base.py", line 245, in _catch_revision_errors
    raise util.CommandError(resolution) from re
alembic.util.exc.CommandError: Can't locate revision identified by '0002_merge_to_asset_references'
Failed to initialize database. Please ensure you have installed the latest requirements. If the error persists, please report this as in future the database will be required: Can't locate revision identified by '0002_merge_to_asset_references'
Starting server

To see the GUI go to: http://127.0.0.1:8188
fast DB scan failed for models: 'NoneType' object is not callable
Traceback (most recent call last):
  File "D:\ComfyUI\app\assets\scanner.py", line 36, in seed_assets
    survivors: set[str] = _fast_db_consistency_pass(r, collect_existing_paths=True, update_missing_tags=True)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\app\assets\scanner.py", line 156, in _fast_db_consistency_pass
    with create_session() as sess:
         ^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\app\database\db.py", line 112, in create_session
    return Session()
           ^^^^^^^^^
TypeError: 'NoneType' object is not callable
orphan pruning failed: 'NoneType' object is not callable
Traceback (most recent call last):
  File "D:\ComfyUI\app\assets\scanner.py", line 43, in seed_assets
    orphans_pruned = _prune_orphaned_assets(roots)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\app\assets\scanner.py", line 123, in _prune_orphaned_assets
    with create_session() as sess:
         ^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\app\database\db.py", line 112, in create_session
    return Session()
           ^^^^^^^^^
TypeError: 'NoneType' object is not callable
Failed to seed assets: 'NoneType' object is not callable
fast DB scan failed for models: 'NoneType' object is not callable
Traceback (most recent call last):
  File "D:\ComfyUI\app\assets\scanner.py", line 36, in seed_assets
    survivors: set[str] = _fast_db_consistency_pass(r, collect_existing_paths=True, update_missing_tags=True)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\app\assets\scanner.py", line 156, in _fast_db_consistency_pass
    with create_session() as sess:
         ^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\app\database\db.py", line 112, in create_session
    return Session()
           ^^^^^^^^^
TypeError: 'NoneType' object is not callable
orphan pruning failed: 'NoneType' object is not callable
Traceback (most recent call last):
  File "D:\ComfyUI\app\assets\scanner.py", line 43, in seed_assets
    orphans_pruned = _prune_orphaned_assets(roots)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\app\assets\scanner.py", line 123, in _prune_orphaned_assets
    with create_session() as sess:
         ^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\app\database\db.py", line 112, in create_session
    return Session()
           ^^^^^^^^^
TypeError: 'NoneType' object is not callable
Failed to seed assets: 'NoneType' object is not callable
这个报错的核心是:ComfyUI 的 SQLite 数据库迁移文件损坏 / 缺失(找不到 0002_merge_to_asset_references 这个数据库版本记录),导致数据库初始化失败,进而引发模型扫描、资产管理等一系列连锁错误。
 
虽然界面能打开(http://127.0.0.1:8188),但模型扫描、资产管理功能会失效,必须修复数据库问题才能正常使用。
 

 

方案一:重置 ComfyUI 数据库(最推荐,5 分钟搞定)

 
这是最简单、最彻底的修复方式,不会影响你的模型 / 节点,只是重置数据库记录:
 

步骤 1:关闭 ComfyUI

 
先关掉正在运行的 ComfyUI 窗口 / 进程,确保完全退出。
 

步骤 2:删除损坏的数据库文件

 
找到 ComfyUI 根目录下的 comfyui.db 文件(SQLite 数据库文件),直接删除:
 
plaintext
 
D:\ComfyUI\comfyui.db
 
这个文件是自动生成的,删除后重启 ComfyUI 会重建一个干净的数据库。
 

步骤 3:删除旧的数据库迁移缓存(可选)

 
如果删除 comfyui.db 后仍报错,删除迁移缓存目录:
 
plaintext
 
D:\ComfyUI\alembic_db\versions\
 
 
(保留 alembic.inienv.py,只删 versions 文件夹里的文件)
 

步骤 4:重启 ComfyUI

 
重新运行 run_nvidia_gpu.bat(或你的启动脚本),ComfyUI 会:
 
  1. 自动重建 comfyui.db 数据库;
  2. 重新执行数据库迁移,生成完整的版本记录;
  3. 重新扫描你的模型 / 资产,恢复正常。
 

 

方案二:修复数据库迁移依赖(补充方案)

 
如果方案一执行后仍提示「找不到迁移版本」,说明迁移依赖缺失,执行以下命令:
 

步骤 1:打开 ComfyUI 终端

 
进入 ComfyUI 根目录,用自带的 Python 执行命令:
 
bash运行
 
# 升级 alembic(数据库迁移工具)
python -m pip install --upgrade alembic --force-reinstall
# 重装 ComfyUI 核心依赖
python -m pip install -r requirements.txt --force-reinstall
 
 

步骤 2:手动执行数据库迁移

 
bash运行
 
# 进入 alembic 目录
cd D:\ComfyUI\alembic_db
# 初始化迁移(如果提示版本不存在,执行这个)
python -m alembic revision --autogenerate -m "fix 0002_merge_to_asset_references"
# 执行升级
python -m alembic upgrade head
 
 

步骤 3:重启 ComfyUI

 
此时数据库迁移会正常执行,不会再提示找不到 0002_merge_to_asset_references
 

 

方案三:降级 ComfyUI(应急方案,适合新版本兼容问题)

 
如果是升级 ComfyUI 后出现的问题,说明新版本数据库迁移有 Bug,临时降级到稳定版:
 

步骤 1:回滚 ComfyUI 版本

 
bash运行
 
# 进入 ComfyUI 根目录
cd D:\ComfyUI
# 回滚到 2025 年稳定版(无数据库迁移 Bug)
git reset --hard 4c859e0
 

步骤 2:删除数据库文件,重启

 
删除 comfyui.db,重新启动 ComfyUI 即可。
 

 

关键注意事项

 
  1. 删除 comfyui.db 不影响你的数据
     

    这个文件只是模型 / 资产的索引记录,删除后 ComfyUI 会重新扫描 models/ 目录,重建索引,不会丢失模型 / 节点 / 工作流;

  2. 不要手动修改 alembic_db 目录
     

    里面的迁移文件是自动生成的,手动改会导致版本混乱;

  3. 启动后耐心等待扫描
     

    重建数据库后,首次启动会扫描所有模型,可能需要几十秒,属于正常现象。

 

 

总结

 
  1. 核心原因:ComfyUI 的 SQLite 数据库迁移版本记录缺失 / 损坏;
  2. 优先方案:删除 comfyui.db 重建数据库,99% 能解决问题;
  3. 补充方案:重装 alembic 依赖,手动执行数据库迁移;
  4. 应急方案:降级 ComfyUI 到稳定版。
 
按方案一操作后,重启 ComfyUI 就能正常使用,模型扫描、资产管理功能都会恢复,不会再出现 NoneType 或数据库迁移报错。
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享