ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

Failed to initialize database.

Open DevilsCrypto opened this issue 7 months ago • 13 comments

Custom Node Testing

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
<OUTPUT OMITTED>
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

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).

DevilsCrypto avatar Jul 02 '25 08:07 DevilsCrypto

Same error, but in my case user folder exists and error still persists

qnub avatar Jul 03 '25 06:07 qnub

Same error, but in my case user folder exists and error still persists

Yes, but does it exist in the ComfyUI directory or within your base_directory? Within my base_directory it was also there precreated, but the error comes from the missing folder in the ComfyUI directory.

DevilsCrypto avatar Jul 03 '25 07:07 DevilsCrypto

Same error as OP, fixed by going to the base_directory C:\Users\YOUR_USERNAME_HERE\AppData\Local\Programs@comfyorgcomfyui-electron\resources\ComfyUI . And by going there and creating a folder named user it solved the error.

CyberAlex93 avatar Jul 12 '25 18:07 CyberAlex93

Same error as OP, fixed by going to the base_directory C:\Users\YOUR_USERNAME_HERE\AppData\Local\Programs@comfyorgcomfyui-electron\resources\ComfyUI . And by going there and creating a folder named user it solved the error.

Solved it for me

DanieleR87 avatar Jul 26 '25 18:07 DanieleR87

I'm getting this also with a default install of the Mac desktop install. The user folder exists already

yuletide avatar Jul 30 '25 22:07 yuletide

  • for macos, go to folder /Applications/ComfyUI.app/Contents/Resources/ComfyUI, and create a folder named user inside it .

uptonking avatar Jul 31 '25 21:07 uptonking

I ended up just installing from source with help from ChatGPT -- no issues now!

yuletide avatar Aug 02 '25 20:08 yuletide

  • for macos, go to folder /Applications/ComfyUI.app/Contents/Resources/ComfyUI, and create a folder named user inside it .

This is definitely a bug as the database shouldn't be being stored in the Application folder. That would mean if you delete the ComfyUI app the database would be deleted. It should be being stored in the base user directory.

Morac2 avatar Aug 31 '25 05:08 Morac2

I ended up just installing from source with help from ChatGPT -- no issues now!

So did I too. Except I used Copilots deep think from ChatGPT. Everything seems to be working fine for me now. no more ComfyUI error messages.

JimmyAlan avatar Sep 08 '25 07:09 JimmyAlan

I ended up just installing from source with help from ChatGPT -- no issues now!

So did I too. Except I used Copilots deep think from ChatGPT. Everything seems to be working fine for me now. no more ComfyUI error messages.

What do you mean by installing from source?

I don’t see how reinstalling would fix anything as the code is still designed to expect the database in a user folder from where it’s executed from. It doesn’t use the base-directory directory at all.

Morac2 avatar Sep 08 '25 12:09 Morac2

I ended up just installing from source with help from ChatGPT -- no issues now!

So did I too. Except I used Copilots deep think from ChatGPT. Everything seems to be working fine for me now. no more ComfyUI error messages.

What do you mean by installing from source?

I don’t see how reinstalling would fix anything as the code is still designed to expect the database in a user folder from where it’s executed from. It doesn’t use the base-directory directory at all.

Just revising: From source, use git to clone the repository by typing 'git clone https://github.com/comfyanonymous/ComfyUI.git' in a directory, preferably C:
in your terminal or cmd or powershell prompt, then cd in into it. make an environment. But you should ask one of the AI assistants to help you build Comfyui from source.

I was using the standalone windows installer version. I couldn't get it fixed, so I just git cloned the source and built from it, but if you decide to do that ask either Copilot or ChatGPT for help installing comfyui from source. because you're going to need to make an env with python -m venv venv inside the clone repository and then get into it by typing: '..venv\scripts\activate.ps1,' and make sure you pip3(if you're using the 3.xxv of python to install torch, triton if needed, and safetensors) if needed too, but definitely torch inside of the venv environment in your terminal. The .venv environment should look something like this: '(venv) C:\yourpath to ComfyUI' inside of your terminal if you're using window. But yet, definitely use one of the two AI assistants to help you out, because there are other steps you need to do to get it working properly. And if you're on *nix or WSL, make sure you ask one of them for install help on them. I hope it helps and works for you. But other than why it works from source, probably because you're building it for your hardware.

JimmyAlan avatar Sep 08 '25 23:09 JimmyAlan

I get this same error on a fresh install on MacOS using Homebrew and manually creating the user folder does not resolve the issue.

iamwillbar avatar Oct 13 '25 00:10 iamwillbar

Same error as OP, fixed by going to the base_directory C:\Users\YOUR_USERNAME_HERE\AppData\Local\Programs@comfyorgcomfyui-electron\resources\ComfyUI . And by going there and creating a folder named user it solved the error.

Solved it for me !!!

hongkebobby avatar Dec 22 '25 11:12 hongkebobby

OP와 같은 오류였고, base_directory C:\Users\YOUR_USERNAME_HERE\AppData\Local\Programs@comfyorgcomfyui-electron\resources\ComfyUI 로 가서 해결했습니다. 거기서 사용자 폴더를 만들자 오류가 해결됐습니다.

저도 정확히 같은 문제였는데, 이 방법으로 해결되었습니다. 감사합니다!!

toorn avatar Jan 03 '26 17:01 toorn