You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
docker downgrade from v2.0.0-beta.2 to 1.9.0 faild #26091
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.9.0
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
use docker downgrade from v2.0.0-beta.2 to 1.9.0 fialed
2025-09-23 11:30:00 /bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
2025-09-23 11:30:00 /entrypoint.sh: line 7: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
2025-09-23 11:30:23 INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
2025-09-23 11:30:23 INFO [alembic.runtime.migration] Will assume transactional DDL.
2025-09-23 11:30:23 ERROR [flask_migrate] Error: Can't locate revision identified by 'b45e25c2d166'
I try to execute these command but the the docker-api-1 failed and restart:
uv run flask db downgrade cf7c38a32b2d
uv run flask db upgrade
uv run flask transform-datasource-credentials
then i add sleeep command and execute these commands but still the same faild
$ uv run flask db downgrade cf7c38a32b2d
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
ERROR [flask_migrate] Error: Can't locate revision identified by 'b45e25c2d166'
Downgrading Dify from v2.0.0-beta.2 to 1.9.0 fails because the database contains Alembic migration revisions (like b45e25c2d166) that do not exist in the 1.9.0 codebase. This happens because newer versions add migrations that older versions can't recognize, so Alembic can't find the revision and the migration fails.
To work around this, you can manually fix the database version conflict by stopping Dify, exposing the PostgreSQL port, connecting to the database, and deleting the problematic revision record from the alembic_version table. After that, restart Dify and the migration should proceed. Always back up your database before making changes. Here’s a step-by-step guide:
Stop Dify: docker compose down
Expose PostgreSQL port in your docker-compose.yaml (e.g., 5432:5432).
Restart Dify: docker compose up -d
Connect to your database (default: user postgres, password difyai123456).
In the database, go to dify -> public -> alembic_version and delete the row with the problematic revision (b45e25c2d166).
Restart Dify again.
Manual downgrades are risky and may require further schema changes, so always test on a backup or staging environment first. More details and community solutions are discussed here.
If automatic migration still fails, you may need to manually execute SQL statements from migration files directly in the database. After any manual fix, restart your containers with docker compose down and docker compose up -d as recommended here.
Downgrades are not officially supported and may require significant manual work. Always back up your data before attempting!
thanks for your feedback. If you want to upgrade Dify‘s version form 2.0.0-beta.2 to 1.9.0, you need downgrade your db migration to cf7c38a32b2d in the 2.0.0-beta.2 envrionment, then you can update your version to 1.9.0@Riding-A-Colt
thanks for your feedback. If you want to upgrade Dify‘s version form 2.0.0-beta.2 to 1.9.0, you need downgrade your db migration to cf7c38a32b2d in the 2.0.0-beta.2 envrionment, then you can update your version to 1.9.0@Riding-A-Colt
I checkout back to 2.0.0-beta.2 and execute uv run flask db downgrade cf7c38a32b2d in the docker-api-1 container but did't work:
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
ERROR [flask_migrate] Error: Can't locate revision identified by 'cf7c38a32b2d'
The same issue occurred when downgrading from 2.0.0-beta. 2 to 1.8.0, and now upgrading to 1.9.0. I also executed the 'docker exec it docker-api-1 UV run Flask transform datasource credentials' command, but still encountered errors
I've been pulling git frequently over the past few days, and I started seeing the same error.
It seems a fix was included in the past few days to revert the 2.0.0-beta2 version back to 1.9.0.
This appears to have caused this issue due to a series of compatibility problems.
I don't understand why you'd want to downgrade to 1.9.0, but if you just want Dify to work in 2.0.0-beta2, you might try temporarily reverting the following commit.
I encountered the same problem. The root cause is that cf7c38a32b2d belongs to the 1.9.0 migration branch, so it cannot be reached directly from 2.0.0-beta.2. b95962a3885c is the common parent revision of both 1.9.0 and 2.0.0-beta.2.
Following these steps, I successfully downgraded to 1.9.0 while keeping the app, plugins, and other data intact. Backup your Dify database before attempting this.
Steps
Checkout 2.0.0-beta.2:
git checkout 2.0.0-beta.2
cd api
Modify migration files to handle PostgreSQL constraints and UUID conversions:
• Add NOT NULL column with default
• Use postgresql_using for UUID conversions
Execute downgrade to the common parent revision:
uv run flask db downgrade b95962a3885c
Restore changes:
git restore .
Checkout 1.9.0 and adjust necessary migrations (if needed), then upgrade:
git checkout 1.9.0
uv run flask db upgrade
uv run flask transform-datasource-credentials
docker compose down
docker compose up -d
Notes / Tips:
• Columns with type changes (e.g., plugin_id to UUID) require postgresql_using to avoid conversion errors.
• Adding NOT NULL columns to existing tables requires either a default value or a two-step process (nullable → populate → set NOT NULL).
• Using the common ancestor revision (b95962a3885c) ensures the downgrade path is valid without breaking Alembic’s migration chain.
This approach preserves all existing app data and avoids full database rebuilds.
# uv run flask db downgrade b95962a3885c
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
INFO [alembic.runtime.migration] Running downgrade 76db8b6ed8f1 -> 8c5088481127, add WorkflowDraftVariableFile
INFO [alembic.runtime.migration] Running downgrade 8c5088481127 -> 17d4db47800c, add_pipeline_info_17
INFO [alembic.runtime.migration] Running downgrade 17d4db47800c -> 74e5f667f4b7, datasource_oauth_refresh
INFO [alembic.runtime.migration] Running downgrade 74e5f667f4b7 -> d3c68680d3ba, add_pipeline_info_15
INFO [alembic.runtime.migration] Running downgrade d3c68680d3ba -> fcb46171d891, add_pipeline_info_14
INFO [alembic.runtime.migration] Running downgrade fcb46171d891 -> 2008609cf2bb, add_pipeline_info_13
INFO [alembic.runtime.migration] Running downgrade 2008609cf2bb -> 1bce102aef9a, add_pipeline_info_12
INFO [alembic.runtime.migration] Running downgrade 1bce102aef9a -> d4a76fde2724, datasource_oauth_2
INFO [alembic.runtime.migration] Running downgrade d4a76fde2724 -> 15e40b74a6d2, datasource_oauth_1
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.DatatypeMismatch: column "plugin_id" cannot be cast automatically to type uuid
HINT: You might need to specify "USING plugin_id::uuid".
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/api/.venv/bin/flask", line 10, in <module>
sys.exit(main())
^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask/cli.py", line 1131, in main
cli.main()
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 1363, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 1830, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 1830, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 1226, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 794, in invoke
return callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/decorators.py", line 34, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask/cli.py", line 400, in decorator
return ctx.invoke(f, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 794, in invoke
return callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask_migrate/cli.py", line 172, in downgrade
_downgrade(directory, revision, sql, tag, x_arg)
File "/app/api/.venv/lib/python3.12/site-packages/flask_migrate/__init__.py", line 111, in wrapped
f(*args, **kwargs)
File "/app/api/.venv/lib/python3.12/site-packages/flask_migrate/__init__.py", line 210, in downgrade
command.downgrade(config, revision, sql=sql, tag=tag)
File "/app/api/.venv/lib/python3.12/site-packages/alembic/command.py", line 530, in downgrade
script.run_env()
File "/app/api/.venv/lib/python3.12/site-packages/alembic/script/base.py", line 551, in run_env
util.load_python_file(self.dir, "env.py")
File "/app/api/.venv/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 116, in load_python_file
module = load_module_py(module_id, path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 136, in load_module_py
spec.loader.exec_module(module) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap_external>", line 999, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/app/api/migrations/env.py", line 109, in <module>
run_migrations_online()
File "/app/api/migrations/env.py", line 103, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/app/api/.venv/lib/python3.12/site-packages/alembic/runtime/environment.py", line 946, in run_migrations
self.get_context().run_migrations(**kw)
File "/app/api/.venv/lib/python3.12/site-packages/alembic/runtime/migration.py", line 627, in run_migrations
step.migration_fn(**kw)
File "/app/api/migrations/versions/2025_07_18_1409-d4a76fde2724_add_pipeline_info_10.py", line 45, in downgrade
with op.batch_alter_table('datasource_oauth_params', schema=None) as batch_op:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/contextlib.py", line 144, in __exit__
next(self.gen)
File "/app/api/.venv/lib/python3.12/site-packages/alembic/operations/base.py", line 397, in batch_alter_table
impl.flush()
File "/app/api/.venv/lib/python3.12/site-packages/alembic/operations/batch.py", line 115, in flush
fn(*arg, **kw)
File "/app/api/.venv/lib/python3.12/site-packages/alembic/ddl/postgresql.py", line 179, in alter_column
self._exec(
File "/app/api/.venv/lib/python3.12/site-packages/alembic/ddl/impl.py", line 246, in _exec
return conn.execute(construct, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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/ddl.py", line 187, in _execute_on_connection
return connection._execute_ddl(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1526, in _execute_ddl
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.DatatypeMismatch) column "plugin_id" cannot be cast automatically to type uuid
HINT: You might need to specify "USING plugin_id::uuid".
[SQL: ALTER TABLE datasource_oauth_params ALTER COLUMN plugin_id TYPE UUID ]
(Background on this error at: https://sqlalche.me/e/20/f405)
withop.batch_alter_table('workflow_draft_variables', schema=None) asbatch_op:
batch_op.add_column(
sa.Column(
'file_id',
models.types.StringUUID(),
nullable=True,
comment='Reference to WorkflowDraftVariableFile if variable is offloaded to external storage'
)
)
""" batch_op.add_column( sa.Column( 'is_default_value', sa.Boolean(), nullable=False, server_default=sa.text(text="FALSE"), comment='Indicates whether the current value is the default for a conversation variable. Always `FALSE` for other types of variables.', ) ) """batch_op.create_index('workflow_draft_variable_file_id_idx', ['file_id'], unique=False)
then, execute the rest upgrade command (uv run flask db upgrade etc.)
@efreykongcn really NEW BEE!following your steps, i successfully downgraded from v2.0.0-beta.2 to 1.9.1 without any errors or warnings!
Thank you so much!
# uv run flask db downgrade b95962a3885c
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
INFO [alembic.runtime.migration] Running downgrade 76db8b6ed8f1 -> 8c5088481127, add WorkflowDraftVariableFile
INFO [alembic.runtime.migration] Running downgrade 8c5088481127 -> 17d4db47800c, add_pipeline_info_17
INFO [alembic.runtime.migration] Running downgrade 17d4db47800c -> 74e5f667f4b7, datasource_oauth_refresh
INFO [alembic.runtime.migration] Running downgrade 74e5f667f4b7 -> d3c68680d3ba, add_pipeline_info_15
INFO [alembic.runtime.migration] Running downgrade d3c68680d3ba -> fcb46171d891, add_pipeline_info_14
INFO [alembic.runtime.migration] Running downgrade fcb46171d891 -> 2008609cf2bb, add_pipeline_info_13
INFO [alembic.runtime.migration] Running downgrade 2008609cf2bb -> 1bce102aef9a, add_pipeline_info_12
INFO [alembic.runtime.migration] Running downgrade 1bce102aef9a -> d4a76fde2724, datasource_oauth_2
INFO [alembic.runtime.migration] Running downgrade d4a76fde2724 -> 15e40b74a6d2, datasource_oauth_1
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.DatatypeMismatch: column "plugin_id" cannot be cast automatically to type uuid
HINT: You might need to specify "USING plugin_id::uuid".
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/api/.venv/bin/flask", line 10, in <module>
sys.exit(main())
^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask/cli.py", line 1131, in main
cli.main()
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 1363, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 1830, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 1830, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 1226, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 794, in invoke
return callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/decorators.py", line 34, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask/cli.py", line 400, in decorator
return ctx.invoke(f, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/click/core.py", line 794, in invoke
return callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask_migrate/cli.py", line 172, in downgrade
_downgrade(directory, revision, sql, tag, x_arg)
File "/app/api/.venv/lib/python3.12/site-packages/flask_migrate/__init__.py", line 111, in wrapped
f(*args, **kwargs)
File "/app/api/.venv/lib/python3.12/site-packages/flask_migrate/__init__.py", line 210, in downgrade
command.downgrade(config, revision, sql=sql, tag=tag)
File "/app/api/.venv/lib/python3.12/site-packages/alembic/command.py", line 530, in downgrade
script.run_env()
File "/app/api/.venv/lib/python3.12/site-packages/alembic/script/base.py", line 551, in run_env
util.load_python_file(self.dir, "env.py")
File "/app/api/.venv/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 116, in load_python_file
module = load_module_py(module_id, path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 136, in load_module_py
spec.loader.exec_module(module) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap_external>", line 999, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/app/api/migrations/env.py", line 109, in <module>
run_migrations_online()
File "/app/api/migrations/env.py", line 103, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/app/api/.venv/lib/python3.12/site-packages/alembic/runtime/environment.py", line 946, in run_migrations
self.get_context().run_migrations(**kw)
File "/app/api/.venv/lib/python3.12/site-packages/alembic/runtime/migration.py", line 627, in run_migrations
step.migration_fn(**kw)
File "/app/api/migrations/versions/2025_07_18_1409-d4a76fde2724_add_pipeline_info_10.py", line 45, in downgrade
with op.batch_alter_table('datasource_oauth_params', schema=None) as batch_op:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/contextlib.py", line 144, in __exit__
next(self.gen)
File "/app/api/.venv/lib/python3.12/site-packages/alembic/operations/base.py", line 397, in batch_alter_table
impl.flush()
File "/app/api/.venv/lib/python3.12/site-packages/alembic/operations/batch.py", line 115, in flush
fn(*arg, **kw)
File "/app/api/.venv/lib/python3.12/site-packages/alembic/ddl/postgresql.py", line 179, in alter_column
self._exec(
File "/app/api/.venv/lib/python3.12/site-packages/alembic/ddl/impl.py", line 246, in _exec
return conn.execute(construct, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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/ddl.py", line 187, in _execute_on_connection
return connection._execute_ddl(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1526, in _execute_ddl
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.DatatypeMismatch) column "plugin_id" cannot be cast automatically to type uuid
HINT: You might need to specify "USING plugin_id::uuid".
[SQL: ALTER TABLE datasource_oauth_params ALTER COLUMN plugin_id TYPE UUID ]
(Background on this error at: https://sqlalche.me/e/20/f405)
Activity
dosubot commentedon Sep 23, 2025
Hi @Riding-A-Colt! I'm Dosu and I’m helping the dify team.
Downgrading Dify from v2.0.0-beta.2 to 1.9.0 fails because the database contains Alembic migration revisions (like
b45e25c2d166) that do not exist in the 1.9.0 codebase. This happens because newer versions add migrations that older versions can't recognize, so Alembic can't find the revision and the migration fails.To work around this, you can manually fix the database version conflict by stopping Dify, exposing the PostgreSQL port, connecting to the database, and deleting the problematic revision record from the
alembic_versiontable. After that, restart Dify and the migration should proceed. Always back up your database before making changes. Here’s a step-by-step guide:docker compose downdocker-compose.yaml(e.g.,5432:5432).docker compose up -dpostgres, passworddifyai123456).dify -> public -> alembic_versionand delete the row with the problematic revision (b45e25c2d166).Manual downgrades are risky and may require further schema changes, so always test on a backup or staging environment first. More details and community solutions are discussed here.
If automatic migration still fails, you may need to manually execute SQL statements from migration files directly in the database. After any manual fix, restart your containers with
docker compose downanddocker compose up -das recommended here.Downgrades are not officially supported and may require significant manual work. Always back up your data before attempting!
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

crazywoola commentedon Sep 23, 2025
Try to run
uv run flask db downgradeanduv run flask db upgradein the container.Tabll commentedon Sep 24, 2025
downgrade encountered the same issue, so it's better to stay on 2.0.0-beta.2 for now.
Additionally, what is the relationship between 1.9.0 and 2.0.0-beta.2? Will there be a direct upgrade path from 2.0.0-beta.2 to future 2.x versions?
JohnJyong commentedon Sep 24, 2025
thanks for your feedback. If you want to upgrade Dify‘s version form
2.0.0-beta.2to1.9.0, you need downgrade your db migration tocf7c38a32b2din the2.0.0-beta.2envrionment, then you can update your version to1.9.0@Riding-A-ColtJohnJyong commentedon Sep 24, 2025
Riding-A-Colt commentedon Sep 24, 2025
I checkout back to 2.0.0-beta.2 and execute
uv run flask db downgrade cf7c38a32b2din the docker-api-1 container but did't work:xuesd commentedon Sep 24, 2025
The same issue occurred when downgrading from 2.0.0-beta. 2 to 1.8.0, and now upgrading to 1.9.0. I also executed the 'docker exec it docker-api-1 UV run Flask transform datasource credentials' command, but still encountered errors
nariba commentedon Sep 24, 2025
I've been pulling git frequently over the past few days, and I started seeing the same error.
It seems a fix was included in the past few days to revert the 2.0.0-beta2 version back to 1.9.0.
This appears to have caused this issue due to a series of compatibility problems.
I don't understand why you'd want to downgrade to 1.9.0, but if you just want Dify to work in 2.0.0-beta2, you might try temporarily reverting the following commit.
efreykongcn commentedon Sep 25, 2025
I encountered the same problem. The root cause is that cf7c38a32b2d belongs to the 1.9.0 migration branch, so it cannot be reached directly from 2.0.0-beta.2. b95962a3885c is the common parent revision of both 1.9.0 and 2.0.0-beta.2.
Following these steps, I successfully downgraded to 1.9.0 while keeping the app, plugins, and other data intact. Backup your Dify database before attempting this.
Steps
git checkout 2.0.0-beta.2 cd apiModify migration files to handle PostgreSQL constraints and UUID conversions:
• Add NOT NULL column with default
• Use postgresql_using for UUID conversions
Execute downgrade to the common parent revision:
uv run flask db downgrade b95962a3885cgit restore .Notes / Tips:
• Columns with type changes (e.g., plugin_id to UUID) require postgresql_using to avoid conversion errors.
• Adding NOT NULL columns to existing tables requires either a default value or a two-step process (nullable → populate → set NOT NULL).
• Using the common ancestor revision (b95962a3885c) ensures the downgrade path is valid without breaking Alembic’s migration chain.
This approach preserves all existing app data and avoids full database rebuilds.
koking0 commentedon Sep 25, 2025
encounter error:
efreykongcn commentedon Sep 25, 2025
Step 2. Modify migration files to handle PostgreSQL constraints and UUID conversions:
Step 5. Checkout the 1.9.0 branch and modify the following migration file:
git checkout 1.9.0then, execute the rest upgrade command (
uv run flask db upgradeetc.)@koking0
koking0 commentedon Sep 25, 2025
@efreykongcn new bee!
Tabll commentedon Oct 9, 2025
@efreykongcn really NEW BEE!following your steps, i successfully downgraded from
v2.0.0-beta.2to1.9.1without any errors or warnings!Thank you so much!
doonygit commentedon Jan 16, 2026
I got zhe same err,how do it?
doonygit commentedon Jan 16, 2026
I get it .
because in api container,the file in migrations\versions is old,should cp the modify file into api container 。