Foreign keys not working properly in SQLite
Bug Description
When creating a flow through the POST /api/v1/flows/ endpoint, I accidentally included an old folder_id in the request body. This folder_id doesn’t exist in the current application.
Even though the flow was successfully created (status 201 Created), it didn’t appear in the UI. I was only able to find it using the api: GET /api/v1/flows/?folder_id={non_existing_folder_id}
Reproduction
Steps to reproduce:
-
Send a
POSTrequest to/api/v1/flows/with a body containing afolder_idthat does not exist but has the right format.The example below uses a minimal payload (default empty flow):
curl --location 'http://localhost:7860/api/v1/flows/' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-api-key: sk-xxxxxxxxxxxxxxxx' \
--data '{
"name": "New Flow",
"data": {
"nodes": [],
"edges": [],
"viewport": {
"zoom": 1,
"x": 0,
"y": 0
}
},
"description": "Graph Your Way to Great Conversations.",
"is_component": false,
"folder_id": "e76a5de1-9a6c-47ce-82d1-50eae943c372",
"icon": null,
"gradient": null,
"endpoint_name": null,
"tags": [],
"mcp_enabled": true
}'
- Observe that the API returns
201 Created. - Open the UI and check the flows list — the new flow is not visible.
- Use the API to
GET /api/v1/flows/?folder_id={non_existing_folder_id}and confirm that the flow was actually created.
Expected behavior
Expected behavior:
If the provided folder_id does not exist, the API should either:
- Return an error (e.g.,
400 Bad Request), or - Automatically assign the flow to a valid default folder (e.g., “root” or “unassigned”).
Actual behavior:
- The flow is created successfully.
- It’s not visible in the UI.
- It can only be retrieved by querying the non-existing
folder_idvia the API.
Who can help?
No response
Operating System
WSL: Ubuntu 22.04
Langflow Version
1.6.4 and 1.6
Python Version
3.10
Screenshot
No response
Flow File
No response
@AntonioABLima,
We have an environment variable that controls the SQLite settings:
LANGFLOW_SQLITE_PRAGMAS = {"synchronous": "NORMAL", "journal_mode": "WAL", "foreign_keys": "ON"}
If you include the property "foreign_keys": "ON", you may encounter errors when working with your JSON data.
By default, foreign key constraints are disabled in SQLite, so you need to enable them manually. In contrast, databases like PostgreSQL have foreign keys enabled by default.
Thank you for your support.
{"detail":"(sqlite3.IntegrityError) FOREIGN KEY constraint failed\n[SQL: INSERT INTO flow (name, description, icon_bg_color, gradient, is_component, updated_at, webhook, endpoint_name, data, mcp_enabled, action_name, action_description, access_type, id, user_id, icon, tags, locked, folder_id, fs_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]\n[parameters: ('New Flow (28)', 'Graph Your Way to Great Conversations.', None, None, 0, '2025-11-03 18:39:48.146557', 0, None, '{\"nodes\": [], \"edges\": [], \"viewport\": {\"zoom\": 1, \"x\": 0, \"y\": 0}}', 1, None, None, 'PRIVATE', 'f58d51431e2b470d98ef91373e5d66e0', 'f876ca39f169452cb10071d937628915', None, '[]', 0, 'e76a5de19a6c47ce82d150eae943c372', None)]\n(Background on this error at: https://sqlalche.me/e/20/gkpj)"}
Thank you @Cristhianzl! For anyone who wants to set the variable manually, you can use:
export LANGFLOW_SQLITE_PRAGMAS='{"synchronous": "NORMAL", "journal_mode": "WAL", "foreign_keys": "ON"}'