sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidColumnReference) there is no unique or exclusion constraint matching the ON CONFLICT specification #16256

Closed
opened 2026-02-21 19:25:20 -05:00 by yindo · 7 comments
Owner

Originally created by @EvilCalf on GitHub (Aug 18, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.7.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Just Run the workflow

✔️ Expected Behavior

Success

Actual Behavior

[2025-08-19 02:46:28 +0000] [35] [ERROR] Error handling request
Traceback (most recent call last):
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1963, in _exec_single_context
    self.dialect.do_execute(
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 943, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.InvalidColumnReference: there is no unique or exclusion constraint matching the ON CONFLICT specification


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/api/.venv/lib/python3.12/site-packages/gunicorn/workers/base_async.py", line 114, in handle_request
    for item in respiter:
                ^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/wsgi.py", line 256, in __next__
    return self._next()
           ^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/wrappers/response.py", line 32, in _iter_encoded
    for item in iterable:
                ^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask/helpers.py", line 125, in generator
    yield from gen
  File "/app/api/libs/helper.py", line 212, in generate
    yield from response
  File "/app/api/core/app/features/rate_limiting/rate_limit.py", line 116, in __next__
    return next(self.generator)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/app/apps/base_app_generator.py", line 165, in gen
    for message in generator:
                   ^^^^^^^^^
  File "/app/api/core/app/apps/base_app_generate_response_converter.py", line 25, in _generate_full_response
    yield from cls.convert_stream_full_response(response)
  File "/app/api/core/app/apps/workflow/generate_response_converter.py", line 46, in convert_stream_full_response
    for chunk in stream_response:
                 ^^^^^^^^^^^^^^^
  File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 193, in _to_stream_response
    for stream_response in generator:
                           ^^^^^^^^^
  File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 224, in _wrapper_process_stream_response
    for response in self._process_stream_response(tts_publisher=tts_publisher, trace_manager=trace_manager):
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 733, in _process_stream_response
    if responses := list(
                    ^^^^^
  File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 649, in _dispatch_event
    yield from handler(
  File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 345, in _handle_node_succeeded_event
    self._save_output_for_event(event, workflow_node_execution.id)
  File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 796, in _save_output_for_event
    saver.save(event.process_data, event.outputs)
  File "/app/api/services/workflow_draft_variable_service.py", line 724, in save
    _batch_upsert_draft_variable(self._session, draft_vars)
  File "/app/api/services/workflow_draft_variable_service.py", line 485, in _batch_upsert_draft_variable
    session.execute(stmt)
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2365, in execute
    return self._execute_internal(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2251, in _execute_internal
    result: Result[Any] = compile_state_cls.orm_execute_statement(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/bulk_persistence.py", line 1294, in orm_execute_statement
    result = conn.execute(
             ^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1415, in execute
    return meth(
           ^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 523, in _execute_on_connection
    return connection._execute_clauseelement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1637, in _execute_clauseelement
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1842, in _execute_context
    return self._exec_single_context(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1982, in _exec_single_context
    self._handle_dbapi_exception(
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2351, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1963, in _exec_single_context
    self.dialect.do_execute(
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 943, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidColumnReference) there is no unique or exclusion constraint matching the ON CONFLICT specification
Originally created by @EvilCalf on GitHub (Aug 18, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.7.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Just Run the workflow ### ✔️ Expected Behavior Success ### ❌ Actual Behavior ``` [2025-08-19 02:46:28 +0000] [35] [ERROR] Error handling request Traceback (most recent call last): File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1963, in _exec_single_context self.dialect.do_execute( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 943, in do_execute cursor.execute(statement, parameters) psycopg2.errors.InvalidColumnReference: there is no unique or exclusion constraint matching the ON CONFLICT specification The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/api/.venv/lib/python3.12/site-packages/gunicorn/workers/base_async.py", line 114, in handle_request for item in respiter: ^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/wsgi.py", line 256, in __next__ return self._next() ^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/wrappers/response.py", line 32, in _iter_encoded for item in iterable: ^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask/helpers.py", line 125, in generator yield from gen File "/app/api/libs/helper.py", line 212, in generate yield from response File "/app/api/core/app/features/rate_limiting/rate_limit.py", line 116, in __next__ return next(self.generator) ^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/base_app_generator.py", line 165, in gen for message in generator: ^^^^^^^^^ File "/app/api/core/app/apps/base_app_generate_response_converter.py", line 25, in _generate_full_response yield from cls.convert_stream_full_response(response) File "/app/api/core/app/apps/workflow/generate_response_converter.py", line 46, in convert_stream_full_response for chunk in stream_response: ^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 193, in _to_stream_response for stream_response in generator: ^^^^^^^^^ File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 224, in _wrapper_process_stream_response for response in self._process_stream_response(tts_publisher=tts_publisher, trace_manager=trace_manager): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 733, in _process_stream_response if responses := list( ^^^^^ File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 649, in _dispatch_event yield from handler( File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 345, in _handle_node_succeeded_event self._save_output_for_event(event, workflow_node_execution.id) File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 796, in _save_output_for_event saver.save(event.process_data, event.outputs) File "/app/api/services/workflow_draft_variable_service.py", line 724, in save _batch_upsert_draft_variable(self._session, draft_vars) File "/app/api/services/workflow_draft_variable_service.py", line 485, in _batch_upsert_draft_variable session.execute(stmt) File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2365, in execute return self._execute_internal( ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2251, in _execute_internal result: Result[Any] = compile_state_cls.orm_execute_statement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/bulk_persistence.py", line 1294, in orm_execute_statement result = conn.execute( ^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1415, in execute return meth( ^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 523, in _execute_on_connection return connection._execute_clauseelement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1637, in _execute_clauseelement ret = self._execute_context( ^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1842, in _execute_context return self._exec_single_context( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1982, in _exec_single_context self._handle_dbapi_exception( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2351, in _handle_dbapi_exception raise sqlalchemy_exception.with_traceback(exc_info[2]) from e File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1963, in _exec_single_context self.dialect.do_execute( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 943, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidColumnReference) there is no unique or exclusion constraint matching the ON CONFLICT specification ```
yindo added the 🐞 bug label 2026-02-21 19:25:20 -05:00
yindo closed this issue 2026-02-21 19:25:20 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 18, 2025):

This error happens because your database is missing a unique constraint on the columns (app_id, node_id, name) in the workflow_draft_variables table, which is required for the upsert (ON CONFLICT) logic to work in Dify workflows. The code and migrations define this constraint, but it looks like it wasn't applied to your live database—often due to a missed or failed migration during deployment.

To fix this, check your database for the constraint (for example, using \d workflow_draft_variables in psql or your database GUI). If it's missing, make sure all migrations have been applied. You can manually add the constraint with:

ALTER TABLE workflow_draft_variables
ADD CONSTRAINT workflow_draft_variables_app_id_key UNIQUE (app_id, node_id, name);

After adding the constraint, restart your application. This should resolve the error and allow your workflow to run as expected.

Reference:

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 18, 2025): <!-- Answer --> This error happens because your database is missing a unique constraint on the columns (`app_id`, `node_id`, `name`) in the `workflow_draft_variables` table, which is required for the upsert (`ON CONFLICT`) logic to work in Dify workflows. The code and migrations define this constraint, but it looks like it wasn't applied to your live database—often due to a missed or failed migration during deployment. To fix this, check your database for the constraint (for example, using `\d workflow_draft_variables` in `psql` or your database GUI). If it's missing, make sure all migrations have been applied. You can manually add the constraint with: ```sql ALTER TABLE workflow_draft_variables ADD CONSTRAINT workflow_draft_variables_app_id_key UNIQUE (app_id, node_id, name); ``` After adding the constraint, restart your application. This should resolve the error and allow your workflow to run as expected. Reference: - [Model and migration define the unique constraint](https://github.com/langgenius/dify/blob/75199442c16fb2ad1758d1f813b0c9249fc150e9/api/models/workflow.py) - [Migration file creating the constraint](https://github.com/langgenius/dify/blob/75199442c16fb2ad1758d1f813b0c9249fc150e9/api/migrations/versions/2025_05_15_1531-2adcbe1f5dfb_add_workflowdraftvariable_model.py) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b5513d14-dc8a-45e4-a389-781699e5cf69?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b5513d14-dc8a-45e4-a389-781699e5cf69?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b5513d14-dc8a-45e4-a389-781699e5cf69?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b5513d14-dc8a-45e4-a389-781699e5cf69?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b5513d14-dc8a-45e4-a389-781699e5cf69?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b5513d14-dc8a-45e4-a389-781699e5cf69?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b5513d14-dc8a-45e4-a389-781699e5cf69?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/24144)
Author
Owner

@EvilCalf commented on GitHub (Aug 18, 2025):

@dosu

postgres=# \d workflow_draft_variables
Did not find any relation named "workflow_draft_variables".
postgres=# ALTER TABLE workflow_draft_variables ADD CONSTRAINT workflow_draft_variables_app_id_key UNIQUE (app_id, node_id, name);
ERROR:  relation "workflow_draft_variables" does not exist
postgres=# 
@EvilCalf commented on GitHub (Aug 18, 2025): [@dosu](https://go.dosu.dev/dosubot) ``` postgres=# \d workflow_draft_variables Did not find any relation named "workflow_draft_variables". postgres=# ALTER TABLE workflow_draft_variables ADD CONSTRAINT workflow_draft_variables_app_id_key UNIQUE (app_id, node_id, name); ERROR: relation "workflow_draft_variables" does not exist postgres=# ```
Author
Owner

@dosubot[bot] commented on GitHub (Aug 18, 2025):

Your database is missing the workflow_draft_variables table because the required migration hasn't been applied yet. To fix this, run the following command from your dify/docker directory:

docker compose exec api alembic upgrade head

This will apply all pending migrations and create the missing table and constraints. After running the migration, check your database again with \d workflow_draft_variables to confirm the table exists. If you see errors or the table is still missing, make sure your database container is running (docker ps), restart your services (docker compose down then docker compose up -d), and verify your environment variables in docker-compose.yaml are correct. Manual table creation isn't enough—other schema changes are handled by the migration process. More details: migration troubleshooting, migration file reference.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 18, 2025): <!-- Answer --> Your database is missing the `workflow_draft_variables` table because the required migration hasn't been applied yet. To fix this, run the following command from your `dify/docker` directory: ```bash docker compose exec api alembic upgrade head ``` This will apply all pending migrations and create the missing table and constraints. After running the migration, check your database again with `\d workflow_draft_variables` to confirm the table exists. If you see errors or the table is still missing, make sure your database container is running (`docker ps`), restart your services (`docker compose down` then `docker compose up -d`), and verify your environment variables in `docker-compose.yaml` are correct. Manual table creation isn't enough—other schema changes are handled by the migration process. More details: [migration troubleshooting](https://github.com/langgenius/dify/issues/13350#issuecomment-2642624050), [migration file reference](https://github.com/langgenius/dify/blob/75199442c16fb2ad1758d1f813b0c9249fc150e9/api/migrations/versions/2025_05_15_1531-2adcbe1f5dfb_add_workflowdraftvariable_model.py). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b96eb1b1-aab4-440e-a760-a5b38949ac3f?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b96eb1b1-aab4-440e-a760-a5b38949ac3f?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b96eb1b1-aab4-440e-a760-a5b38949ac3f?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b96eb1b1-aab4-440e-a760-a5b38949ac3f?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b96eb1b1-aab4-440e-a760-a5b38949ac3f?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b96eb1b1-aab4-440e-a760-a5b38949ac3f?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b96eb1b1-aab4-440e-a760-a5b38949ac3f?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/24144)
Author
Owner

@EvilCalf commented on GitHub (Aug 18, 2025):

@dosu

docker compose exec api alembic upgrade head
  FAILED: No 'script_location' key found in configuration.
exit status 255
@EvilCalf commented on GitHub (Aug 18, 2025): [@dosu](https://go.dosu.dev/dosubot) ``` docker compose exec api alembic upgrade head FAILED: No 'script_location' key found in configuration. exit status 255 ```
Author
Owner

@dosubot[bot] commented on GitHub (Aug 18, 2025):

The error happens because Dify manages database migrations using Flask-Migrate and the Flask CLI, not the Alembic CLI. That's why alembic upgrade head fails—it expects a standalone Alembic config (alembic.ini), which isn't present in the Docker setup.

To run migrations and create missing tables like workflow_draft_variables, use the Flask CLI inside your Docker container:

docker compose exec api flask db upgrade

After running this, check your database for the new table. If you still have issues, make sure your migration scripts are present in api/migrations/versions/, and restart your containers with:

docker compose down
docker compose up -d

If migrations continue to fail, check your Docker volumes and environment variables. For more details, see this migration troubleshooting thread and manual migration steps.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 18, 2025): <!-- Answer --> The error happens because Dify manages database migrations using Flask-Migrate and the Flask CLI, not the Alembic CLI. That's why `alembic upgrade head` fails—it expects a standalone Alembic config (`alembic.ini`), which isn't present in the Docker setup. To run migrations and create missing tables like `workflow_draft_variables`, use the Flask CLI inside your Docker container: ```bash docker compose exec api flask db upgrade ``` After running this, check your database for the new table. If you still have issues, make sure your migration scripts are present in `api/migrations/versions/`, and restart your containers with: ```bash docker compose down docker compose up -d ``` If migrations continue to fail, check your Docker volumes and environment variables. For more details, see [this migration troubleshooting thread](https://github.com/langgenius/dify/issues/13350) and [manual migration steps](https://github.com/langgenius/dify/issues/22244). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/027e1204-4e07-4670-a5d7-49d6336891ec?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/027e1204-4e07-4670-a5d7-49d6336891ec?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/027e1204-4e07-4670-a5d7-49d6336891ec?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/027e1204-4e07-4670-a5d7-49d6336891ec?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/027e1204-4e07-4670-a5d7-49d6336891ec?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/027e1204-4e07-4670-a5d7-49d6336891ec?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/027e1204-4e07-4670-a5d7-49d6336891ec?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/24144)
Author
Owner

@EvilCalf commented on GitHub (Aug 18, 2025):

@dosu
I no longer know which updates have been applied and which have not in api/migrations/versions

Is there any way to update all, flask db upgrade is useless

@EvilCalf commented on GitHub (Aug 18, 2025): [@dosu](https://go.dosu.dev/dosubot) I no longer know which updates have been applied and which have not in `api/migrations/versions` Is there any way to update all, `flask db upgrade` is useless
Author
Owner

@dosubot[bot] commented on GitHub (Aug 18, 2025):

You can check which migrations have been applied by running SELECT * FROM alembic_version; in your database. The value shown is the current migration revision. Compare this to the latest migration file name in api/migrations/versions/ (the filename before .py).

If the migration state is out of sync or flask db upgrade isn't working, you can stamp your database to the latest revision with:

docker compose exec api flask db stamp <latest_revision>

Replace <latest_revision> with the newest migration hash from your versions directory.

Then run:

docker compose exec api flask db upgrade

If you still have issues, you may need to manually apply SQL from the migration files or check for schema drift. For more details and troubleshooting steps, see this guide and manual migration steps.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 18, 2025): <!-- Answer --> You can check which migrations have been applied by running `SELECT * FROM alembic_version;` in your database. The value shown is the current migration revision. Compare this to the latest migration file name in `api/migrations/versions/` (the filename before `.py`). If the migration state is out of sync or `flask db upgrade` isn't working, you can stamp your database to the latest revision with: ```bash docker compose exec api flask db stamp <latest_revision> ``` Replace `<latest_revision>` with the newest migration hash from your versions directory. Then run: ```bash docker compose exec api flask db upgrade ``` If you still have issues, you may need to manually apply SQL from the migration files or check for schema drift. For more details and troubleshooting steps, see [this guide](https://github.com/langgenius/dify/issues/22961#issuecomment-3116882773) and [manual migration steps](https://github.com/langgenius/dify/issues/22244). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/5b3b9509-39df-498c-b958-b585aff8b00a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/5b3b9509-39df-498c-b958-b585aff8b00a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/5b3b9509-39df-498c-b958-b585aff8b00a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/5b3b9509-39df-498c-b958-b585aff8b00a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5b3b9509-39df-498c-b958-b585aff8b00a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/5b3b9509-39df-498c-b958-b585aff8b00a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5b3b9509-39df-498c-b958-b585aff8b00a?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/24144)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#16256