langflow-ai/langflow · error · RuntimeError
Could not create default folder.
Error message
Could not create default folder.
What it means
During 'langflow superuser' creation, after the user row is created the CLI attempts get_or_create_default_folder for the new superuser. If that helper returns a falsy result (folder not returned/created), the command raises RuntimeError('Could not create default folder.'), leaving the superuser existing but without a default folder. Root causes are typically database issues: failed commit, migration drift, or a folder-creation helper that returned None on conflict.
Source
Thrown at src/backend/base/langflow/__main__.py:964
from langflow.services.deps import get_auth_service
auth = get_auth_service()
if await auth.create_super_user(username, password, db=session):
# Verify that the superuser was created
from langflow.services.database.models.user.model import User
stmt = select(User).where(User.username == username)
created_user: User = (await session.exec(stmt)).first()
if created_user is None or not created_user.is_superuser:
typer.echo("Superuser creation failed.")
return
# Now create the first folder for the user
result = await get_or_create_default_folder(session, created_user.id)
if result:
typer.echo("Default folder created successfully.")
else:
msg = "Could not create default folder."
raise RuntimeError(msg)
# Log the superuser creation for audit purposes
logger.warning(
f"SECURITY AUDIT: New superuser '{username}' created via CLI command"
+ (" by authenticated user" if auth_token else " (first-time setup)")
)
typer.echo("Superuser created successfully.")
else:
logger.error(f"SECURITY AUDIT: Failed attempt to create superuser '{username}' via CLI")
typer.echo("Superuser creation failed.")
@app.command(name="migrate-mcp")
def migrate_mcp(
log_level: str = typer.Option("info", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"),
dry_run: bool = typer.Option(default=False, help="Report what would be imported without writing."), # noqa: FBT001
) -> None:View on GitHub (pinned to 976ec789d2)
Solutions
- Run migrations before creating the superuser: 'langflow migration' (or make alembic-upgrade in dev).
- Re-run the superuser command — the user already exists, but verify a default folder is present and create it via the API if not.
- Check DB connectivity/permissions (SQLite path writable; Postgres reachable) and inspect logs for the underlying folder-creation error.
Example fix
# before langflow superuser --username admin --password ... # RuntimeError: Could not create default folder. # after langflow migration langflow superuser --username admin --password ...
Defensive patterns
Strategy: try-catch
Try / catch
try:
run_superuser_command(...)
except RuntimeError as e:
if "default folder" in str(e):
# user exists; verify/repair the folder out-of-band
repair_default_folder(username)
else:
raise Prevention
- Run 'langflow migration' before first superuser creation.
- Script first-run setup as: migrate -> superuser -> verify folder, with retries around DB flakiness.
- Keep the DB reachable and migrated before any user-provisioning CLI.
When it happens
Trigger: langflow superuser --username ... --password ... where user creation succeeds but get_or_create_default_folder(session, user_id) returns falsy; flaky DB connection mid-command; schema out of date relative to code.
Common situations: First-run setup against a database missing the folder table (stale migrations); SQLite file permission problems; Postgres briefly unavailable during the second write.
Related errors
- provider directory not found: {src}
- destination already exists (already consolidated?): {dst}
- {provider}: source has subdirectory/ies {subdirs} that move_
- ripgrep (rg) is required for --rewrite-consumers but was not
- --bundle {bundle!r} is not a valid bundle name (lowercase sn
AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14).
Data as JSON: /api/errors/4f369bfc43476758.
Report an issue: GitHub.