Comfy-Org / Comfy-Org/ComfyUI

Failed to initialize database.

Open
#8,764 17 comments 9 reactions 0 assignees View on GitHub
Potential Bug
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 6h
Merged PRs (30d)
155

Description

### Custom Node Testing

- [x] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)

### Expected Behavior

During a fresh ComfyUI install with the base_directory it should use the user directory in there so store the database.

### Actual Behavior

During the startup the following log is being presented:

```
python main.py --listen 0.0.0.0 --base-directory ../comfyui_data

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: (sqlite3.OperationalError) unable to open database file
(Background on this error at: https://sqlalche.me/e/20/e3q8)
Starting server
```

While trying to find where the error was coming from i found that ComfyUI itself is initializing the database and using the path in app.database.get_db_path

When i add breakpoints to find out the path being used its skipping the base_directory and trying a local folder which does not exist in a fresh install.

Path set by ComfyUI:
ComfyUI/user/comfyui.db

After creating the user folder in ComfyUI by hand the error is being fixed.

### Steps to Reproduce

- Remove ComfyUI completely
- Clone ComfyUI
- Create venv and install requirements
- Create a base directory where you like
- Start comfy with base directory set: python main.py --listen 0.0.0.0 --base-directory BASE_DIR_HERE
- The error should show up during the run

### Debug Logs

```powershell
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: (sqlite3.OperationalError) unable to open database file
(Background on this error at: https://sqlalche.me/e/20/e3q8)
Starting server

To see the GUI go to: http://0.0.0.0:8888
```

### Other

Fixing the issue can be done in multiple ways, but whatever solution is being chosen make sure to always create the user dir during the startup to prevent the error for fresh users.

Preferred fix would be to check if the user sets a base_directory and use the user folder in there (or create user folder first).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.