{"record":{"id":"4f369bfc43476758","repo":"langflow-ai/langflow","slug":"could-not-create-default-folder","errorCode":null,"errorMessage":"Could not create default folder.","messagePattern":"Could not create default folder\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/backend/base/langflow/__main__.py","lineNumber":964,"sourceCode":"        from langflow.services.deps import get_auth_service\n\n        auth = get_auth_service()\n        if await auth.create_super_user(username, password, db=session):\n            # Verify that the superuser was created\n            from langflow.services.database.models.user.model import User\n\n            stmt = select(User).where(User.username == username)\n            created_user: User = (await session.exec(stmt)).first()\n            if created_user is None or not created_user.is_superuser:\n                typer.echo(\"Superuser creation failed.\")\n                return\n            # Now create the first folder for the user\n            result = await get_or_create_default_folder(session, created_user.id)\n            if result:\n                typer.echo(\"Default folder created successfully.\")\n            else:\n                msg = \"Could not create default folder.\"\n                raise RuntimeError(msg)\n\n            # Log the superuser creation for audit purposes\n            logger.warning(\n                f\"SECURITY AUDIT: New superuser '{username}' created via CLI command\"\n                + (\" by authenticated user\" if auth_token else \" (first-time setup)\")\n            )\n            typer.echo(\"Superuser created successfully.\")\n\n        else:\n            logger.error(f\"SECURITY AUDIT: Failed attempt to create superuser '{username}' via CLI\")\n            typer.echo(\"Superuser creation failed.\")\n\n\n@app.command(name=\"migrate-mcp\")\ndef migrate_mcp(\n    log_level: str = typer.Option(\"info\", help=\"Logging level.\", envvar=\"LANGFLOW_LOG_LEVEL\"),\n    dry_run: bool = typer.Option(default=False, help=\"Report what would be imported without writing.\"),  # noqa: FBT001\n) -> None:","sourceCodeStart":946,"sourceCodeEnd":982,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/__main__.py#L946-L982","documentation":"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.","triggerScenarios":"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.","commonSituations":"First-run setup against a database missing the folder table (stale migrations); SQLite file permission problems; Postgres briefly unavailable during the second write.","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."],"exampleFix":"# before\nlangflow superuser --username admin --password ...  # RuntimeError: Could not create default folder.\n# after\nlangflow migration\nlangflow superuser --username admin --password ...","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    run_superuser_command(...)\nexcept RuntimeError as e:\n    if \"default folder\" in str(e):\n        # user exists; verify/repair the folder out-of-band\n        repair_default_folder(username)\n    else:\n        raise","preventionTips":["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."],"tags":["cli","superuser","database","first-run","folders"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}