Skip to content
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

An error occurred during database initialization #14199

Closed
5 tasks done
lovezhou1990 opened this issue Feb 22, 2025 · 2 comments
Closed
5 tasks done

An error occurred during database initialization #14199

lovezhou1990 opened this issue Feb 22, 2025 · 2 comments
Labels
🤔 cant-reproduce We can not reproduce it or the information is limited

Comments

@lovezhou1990
Copy link

lovezhou1990 commented Feb 22, 2025

Self Checks

  • 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 (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

Latest

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

After git clone the latest code, run the "flask db upgrade" command according to the installation procedure and the following error message is displayed:
(non-package-mode-py3.12) D:\workspace\opensource\dify_ws\dify\api>flask db upgrade
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Scripts\flask.exe\__main__.py", line 7, in <module>
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\flask\cli.py", line 1129, in main
    cli.main()
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\click\core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\click\core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\click\core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\click\core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\click\core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\click\decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\flask\cli.py", line 400, in decorator
    return ctx.invoke(f, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\click\core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\flask_migrate\cli.py", line 154, in upgrade
    _upgrade(directory, revision, sql, tag, x_arg)
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\flask_migrate\__init__.py", line 111, in wrapped
    f(*args, **kwargs)
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\flask_migrate\__init__.py", line 200, in upgrade
    command.upgrade(config, revision, sql=sql, tag=tag)
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\alembic\command.py", line 406, in upgrade
    script.run_env()
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\alembic\script\base.py", line 586, in run_env
    util.load_python_file(self.dir, "env.py")
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\alembic\util\pyfiles.py", line 95, in load_python_file
    module = load_module_py(module_id, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\alembic\util\pyfiles.py", line 113, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "D:\workspace\opensource\dify_ws\dify\api\migrations\env.py", line 109, in <module>
    run_migrations_online()
  File "D:\workspace\opensource\dify_ws\dify\api\migrations\env.py", line 93, in run_migrations_online
    with connectable.connect() as connection:
         ^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\engine\base.py", line 3278, in connect
    return self._connection_cls(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\engine\base.py", line 146, in __init__
    self._dbapi_connection = engine.raw_connection()
                             ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\engine\base.py", line 3302, in raw_connection
    return self.pool.connect()
           ^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\pool\base.py", line 449, in connect
    return _ConnectionFairy._checkout(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\pool\base.py", line 1263, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\pool\base.py", line 712, in checkout
    rec = pool._do_get()
          ^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\pool\impl.py", line 179, in _do_get
    with util.safe_reraise():
         ^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\util\langhelpers.py", line 146, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\pool\impl.py", line 177, in _do_get
    return self._create_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\pool\base.py", line 390, in _create_connection
    return _ConnectionRecord(self)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\pool\base.py", line 674, in __init__
    self.__connect()
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\pool\base.py", line 900, in __connect
    with util.safe_reraise():
         ^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\util\langhelpers.py", line 146, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\pool\base.py", line 896, in __connect
    self.dbapi_connection = connection = pool._invoke_creator(self)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\engine\create.py", line 643, in connect
    return dialect.connect(*cargs, **cparams)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\sqlalchemy\engine\default.py", line 621, in connect
    return self.loaded_dbapi.connect(*cargs, **cparams)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\opensource\dify_ws\dify\api\.venv\Lib\site-packages\psycopg2\__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 61: invalid continuation byte

(non-package-mode-py3.12) D:\workspace\opensource\dify_ws\dify\api>

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

Copy link

dosubot bot commented Feb 22, 2025

Hello, @lovezhou1990! I'm here to help you with your technical issues and bugs. Let's work together to resolve the issue you're facing.

I found two similar unsolved discussions related to the flask db upgrade command in Dify:

  1. Source code installation execution command: flask db upgrade [1].
  2. poetry run python -m flask db upgrade 数据库迁移失败 [2].

For the UnicodeDecodeError you're encountering, it might be related to the database connection string or the environment setup. Here are some steps you can take to troubleshoot and resolve the issue:

  1. Check Database Connection String: Ensure that your database connection string is correctly configured and does not contain any non-UTF-8 characters. Dify expects the encoding to be "utf-8" [3].

  2. Environment Setup: Verify that your environment is set up correctly according to the prerequisites for running flask db upgrade in Dify. This includes ensuring that Docker and Docker Compose are installed and running, and that the necessary middleware services (PostgreSQL, Redis) are deployed [4][5].

  3. Database Container: Make sure the database container is running properly. You can check this with docker ps. If there are issues, try stopping all containers, removing existing volumes, and restarting the services [6].

  4. Character Set Configuration: If you are using a specific character set for your database, ensure it is compatible with UTF-8, or adjust the DB_CHARSET parameter in your configuration if needed [3].

These steps should help you identify and resolve the issue with the database initialization error.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot dosubot bot added the 🐞 bug Something isn't working label Feb 22, 2025
@lovezhou1990
Copy link
Author

We have checked that ".env "is in UTF-8 encoding, there is no adjustment elsewhere, and the locally installed postgres database is also in utf-8 format

@crazywoola crazywoola added 🤔 cant-reproduce We can not reproduce it or the information is limited and removed 🐞 bug Something isn't working labels Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 cant-reproduce We can not reproduce it or the information is limited
Projects
None yet
Development

No branches or pull requests

2 participants