Skip to content

Alembic error: NameError: name 'FetchedValue' is not defined #17

Description

@khteh

pipenv run alembic upgrade head hits a NameError:

    created_at: Mapped[datetime] = mapped_column(
        DateTime(timezone=True),
        default=sa.func.now(),
        server_default=sa.FetchedValue()
    )
$ pipenv run alembic upgrade head
Loading .env environment variables...
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> ca93a9d04c54, Initial migration
Traceback (most recent call last):
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/bin/alembic", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/alembic/config.py", line 636, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/alembic/config.py", line 626, in main
    self.run_cmd(cfg, options)
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/alembic/config.py", line 603, in run_cmd
    fn(
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/alembic/command.py", line 408, in upgrade
    script.run_env()
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/alembic/script/base.py", line 586, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
    module = load_module_py(module_id, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/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 "/usr/src/Python/PythonRestAPI/migrations/env.py", line 92, in <module>
    run_migrations_online()
  File "/usr/src/Python/PythonRestAPI/migrations/env.py", line 86, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/alembic/runtime/environment.py", line 946, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/alembic/runtime/migration.py", line 623, in run_migrations
    step.migration_fn(**kw)
  File "/usr/src/Python/PythonRestAPI/migrations/versions/ca93a9d04c54_initial_migration.py", line 30, in upgrade
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=FetchedValue(), nullable=False),
                                                                       ^^^^^^^^^^^^
NameError: name 'FetchedValue' is not defined

OS: Ubuntu 24.10
Python: 3.12.7
Alembic: 1.15.1
SQLAlchemy: 2.0.39
Database: PostgreSQL

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions