-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on startup with Postgres - constraint "fk_flow_user_id_user" for relation "flow" already exists #5371
Comments
To resolve the startup crash in LangFlow with Postgres due to the "fk_flow_user_id_user" constraint already existing, you can modify the Alembic migration script to check for the existence of the foreign key constraint before attempting to create it. Here's a snippet that includes such a check: flow_fks = {fk["name"] for fk in inspector.get_foreign_keys("flow")}
with op.batch_alter_table("flow", schema=None) as batch_op:
if "flow_user_id_fkey" not in flow_fks:
batch_op.create_foreign_key("flow_user_id_fkey", "user", ["user_id"], ["id"]) This modification ensures that the script checks for the existence of the foreign key constraint directly, preventing the attempt to create it if it already exists. Make sure to replace any outdated constraint names with the correct ones used in your database schema, such as "flow_user_id_fkey" instead of "fk_flow_user_id_user" [1][2]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Hi, @ogabrielluiz I see that you worked last in the alembic. I'm getting the same issue. could you give some insight? I'm not starting langflow from the docker, i'm trying to run it locally, and added the url to the .env file |
@devinbost I was able to fix this by updating the upgrade() function in /langflow/src/backend/base/langflow/alembic/versions/b2fa308044b5_add_unique_constraints.py to this:
|
Bug Description
LangFlow is crashing on startup when postgres is enabled. It's giving this exception:
I've experienced this on several of the recent LangFlow versions (starting I think around 1.0.19).
Interestingly, it's saying it's trying to upgrade, but the data directories are totally clear.
Detailed log is here:
docker-compose-postgres-alembic2.log
Reproduction
Expected behavior
LangFlow should start as expected
Who can help?
@Jord
Operating System
Mac M1
Langflow Version
langflowai/langflow-ep:v1.1.1.dev11
Python Version
3.10
Screenshot
No response
Flow File
No response
The text was updated successfully, but these errors were encountered: