Hi all, start prefect2 server failed. Can anyone help? Thanks! ``` File "/Users/shelocks/.pyenv/ve...
g
Hi all, start prefect2 server failed. Can anyone help? Thanks!
Copy code
File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/api/server.py", line 502, in stop_services
    if app.state.services:
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/datastructures.py", line 705, in __getattr__
    raise AttributeError(message.format(self.__class__.__name__, key))
AttributeError: 'State' object has no attribute 'services'

Application startup failed. Exiting.
Server stopped!
1
j
Hi @GuangSheng Liu - would you mind moving your error message into the thread. We try to keep the main channel clean so we can scan through and answer questions as quickly as possible.
It looks as though there’s an issue running migrations and you have a missing table in your database. You can see more about the server and database in the docs: https://docs.prefect.io/latest/host/
g
ok, thanks. detail error info
Copy code
➜  ~ prefect version
Version:             2.10.13
API version:         0.8.4
Python version:      3.9.0
Git commit:          179edeac
Built:               Thu, Jun 8, 2023 4:10 PM
OS/Arch:             darwin/x86_64
Profile:             default
Server type:         ephemeral
Server:
  Database:          sqlite
  SQLite version:    3.24.0
➜  ~
➜  ~
➜  ~ prefect server start

 ___ ___ ___ ___ ___ ___ _____
| _ \ _ \ __| __| __/ __|_   _|
|  _/   / _|| _|| _| (__  | |
|_| |_|_\___|_| |___\___| |_|

Configure Prefect to communicate with the server with:

    prefect config set PREFECT_API_URL=<http://127.0.0.1:4200/api>

View the API reference documentation at <http://127.0.0.1:4200/docs>

Check out the dashboard at <http://127.0.0.1:4200>



Traceback (most recent call last):
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/api/server.py", line 515, in lifespan
    await run_migrations()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/api/server.py", line 438, in run_migrations
    await db.create_db()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/database/interface.py", line 55, in create_db
    await self.run_migrations_upgrade()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/database/interface.py", line 63, in run_migrations_upgrade
    await run_sync_in_worker_thread(alembic_upgrade)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 91, in run_sync_in_worker_thread
    return await anyio.to_thread.run_sync(
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/database/alembic_commands.py", line 24, in wrapper
    return fn(*args, **kwargs)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/database/alembic_commands.py", line 53, in alembic_upgrade
    alembic.command.upgrade(alembic_config(), revision, sql=dry_run)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/alembic/command.py", line 385, in upgrade
    script.run_env()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/alembic/script/base.py", line 582, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 94, in load_python_file
    module = load_module_py(module_id, path)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 110, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/database/migrations/env.py", line 174, in <module>
    apply_migrations()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 243, in coroutine_wrapper
    return run_async_from_worker_thread(async_fn, *args, **kwargs)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 177, in run_async_from_worker_thread
    return anyio.from_thread.run(call)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/anyio/from_thread.py", line 49, in run
    return asynclib.run_async_from_thread(func, *args)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 970, in run_async_from_thread
    return f.result()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/concurrent/futures/_base.py", line 440, in result
    return self.__get_result()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/database/migrations/env.py", line 168, in apply_migrations
    await connection.run_sync(do_run_migrations)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/ext/asyncio/engine.py", line 548, in run_sync
    return await greenlet_spawn(fn, conn, *arg, **kw)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 128, in greenlet_spawn
    result = context.switch(value)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/database/migrations/env.py", line 136, in do_run_migrations
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/alembic/runtime/environment.py", line 928, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/alembic/runtime/migration.py", line 628, in run_migrations
    step.migration_fn(**kw)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/database/migrations/versions/sqlite/2022_04_23_114831_fd966d4ad99c_rename_block_to_blockbasis_and_.py", line 32, in upgrade
    batch_op.drop_constraint("pk_block_data")
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/contextlib.py", line 124, in __exit__
    next(self.gen)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/alembic/operations/base.py", line 377, in batch_alter_table
    impl.flush()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/alembic/operations/batch.py", line 139, in flush
    existing_table = Table(
  File "<string>", line 2, in __new__
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
    return fn(*args, **kwargs)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 617, in __new__
    metadata._remove_table(name, schema)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 612, in __new__
    table._init(name, metadata, *args, **kw)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 687, in _init
    self._autoload(
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 722, in _autoload
    conn_insp.reflect_table(
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 795, in reflect_table
    self._reflect_fk(
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 992, in _reflect_fk
    sa_schema.Table(
  File "<string>", line 2, in __new__
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
    return fn(*args, **kwargs)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 617, in __new__
    metadata._remove_table(name, schema)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 612, in __new__
    table._init(name, metadata, *args, **kw)
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 687, in _init
    self._autoload(
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 722, in _autoload
    conn_insp.reflect_table(
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 789, in reflect_table
    raise exc.NoSuchTableError(table_name)
sqlalchemy.exc.NoSuchTableError: block_spec

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/datastructures.py", line 702, in __getattr__
    return self._state[key]
KeyError: 'services'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/routing.py", line 677, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/contextlib.py", line 175, in __aenter__
    return await self.gen.__anext__()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/api/server.py", line 520, in lifespan
    await stop_services()
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/prefect/server/api/server.py", line 502, in stop_services
    if app.state.services:
  File "/Users/shelocks/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/datastructures.py", line 705, in __getattr__
    raise AttributeError(message.format(self.__class__.__name__, key))
AttributeError: 'State' object has no attribute 'services'

Application startup failed. Exiting.
Server stopped!
I use
Copy code
prefect server database reset -y
to reset database,but still get error
Copy code
stockstart git:(main) ✗ prefect server database reset -y

Downgrading database...
Upgrading database...
Traceback (most recent call last):
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/cli/_utilities.py", line 41, in wrapper
    return fn(*args, **kwargs)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 255, in coroutine_wrapper
    return call()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/_internal/concurrency/calls.py", line 383, in __call__
    return self.result()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/_internal/concurrency/calls.py", line 283, in result
    return self.future.result(timeout=timeout)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/_internal/concurrency/calls.py", line 169, in result
    return self.__get_result()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/_internal/concurrency/calls.py", line 346, in _run_async
    result = await coro
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/cli/server.py", line 194, in reset
    await db.create_db()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/server/database/interface.py", line 55, in create_db
    await self.run_migrations_upgrade()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/server/database/interface.py", line 63, in run_migrations_upgrade
    await run_sync_in_worker_thread(alembic_upgrade)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 91, in run_sync_in_worker_thread
    return await anyio.to_thread.run_sync(
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/anyio/to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/server/database/alembic_commands.py", line 24, in wrapper
    return fn(*args, **kwargs)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/server/database/alembic_commands.py", line 53, in alembic_upgrade
    alembic.command.upgrade(alembic_config(), revision, sql=dry_run)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/alembic/command.py", line 385, in upgrade
    script.run_env()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/alembic/script/base.py", line 582, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 94, in load_python_file
    module = load_module_py(module_id, path)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 110, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/server/database/migrations/env.py", line 174, in <module>
    apply_migrations()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 243, in coroutine_wrapper
    return run_async_from_worker_thread(async_fn, *args, **kwargs)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 177, in run_async_from_worker_thread
    return anyio.from_thread.run(call)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/anyio/from_thread.py", line 47, in run
    return asynclib.run_async_from_thread(func, *args)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 906, in run_async_from_thread
    return f.result()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/concurrent/futures/_base.py", line 446, in result
    return self.__get_result()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/server/database/migrations/env.py", line 168, in apply_migrations
    await connection.run_sync(do_run_migrations)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/ext/asyncio/engine.py", line 872, in run_sync
    return await greenlet_spawn(fn, self._proxied, *arg, **kw)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 192, in greenlet_spawn
    result = context.switch(value)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/server/database/migrations/env.py", line 136, in do_run_migrations
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/alembic/runtime/environment.py", line 928, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/alembic/runtime/migration.py", line 628, in run_migrations
    step.migration_fn(**kw)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/prefect/server/database/migrations/versions/sqlite/2022_04_23_114831_fd966d4ad99c_rename_block_to_blockbasis_and_.py", line 32, in upgrade
    batch_op.drop_constraint("pk_block_data")
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/contextlib.py", line 126, in __exit__
    next(self.gen)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/alembic/operations/base.py", line 377, in batch_alter_table
    impl.flush()
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/alembic/operations/batch.py", line 139, in flush
    existing_table = Table(
  File "<string>", line 2, in __new__
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 434, in __new__
    return cls._new(*args, **kw)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 489, in _new
    metadata._remove_table(name, schema)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 147, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 484, in _new
    table.__init__(name, metadata, *args, _no_init=False, **kw)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 864, in __init__
    self._autoload(
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 896, in _autoload
    conn_insp.reflect_table(
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 1570, in reflect_table
    self._reflect_fk(
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 1770, in _reflect_fk
    sa_schema.Table(
  File "<string>", line 2, in __new__
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 434, in __new__
    return cls._new(*args, **kw)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 489, in _new
    metadata._remove_table(name, schema)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 147, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 484, in _new
    table.__init__(name, metadata, *args, _no_init=False, **kw)
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 864, in __init__
    self._autoload(
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 896, in _autoload
    conn_insp.reflect_table(
  File "/Users/shelocks/.pyenv/versions/3.9.13/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 1538, in reflect_table
    raise exc.NoSuchTableError(table_name)
sqlalchemy.exc.NoSuchTableError: block_spec
change database to postgresql, everything is ok.
👍 1
🚀 1