Airflow - alembic.util.exc.CommandError: Can't locate revision identified by 'a13f7613ad25'
Asked Answered
S

4

7
webserver_1  | The above exception was the direct cause of the following exception:
webserver_1  | 
webserver_1  | Traceback (most recent call last):
webserver_1  |   File "/usr/local/bin/airflow", line 8, in <module>
webserver_1  |     sys.exit(main())
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/airflow/__main__.py", line 40, in main
webserver_1  |     args.func(args)
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/airflow/cli/cli_parser.py", line 48, in command
webserver_1  |     return func(*args, **kwargs)
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/airflow/cli/commands/db_command.py", line 31, in initdb
webserver_1  |     db.initdb()
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/airflow/utils/db.py", line 549, in initdb
webserver_1  |     upgradedb()
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/airflow/utils/db.py", line 684, in upgradedb
webserver_1  |     command.upgrade(config, 'heads')
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/command.py", line 294, in upgrade
webserver_1  |     script.run_env()
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/script/base.py", line 490, in run_env
webserver_1  |     util.load_python_file(self.dir, "env.py")
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 97, in load_python_file
webserver_1  |     module = load_module_py(module_id, path)
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/util/compat.py", line 184, in load_module_py
webserver_1  |     spec.loader.exec_module(module)
webserver_1  |   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
webserver_1  |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/airflow/migrations/env.py", line 108, in <module>
webserver_1  |     run_migrations_online()
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/airflow/migrations/env.py", line 102, in run_migrations_online
webserver_1  |     context.run_migrations()
webserver_1  |   File "<string>", line 8, in run_migrations
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/runtime/environment.py", line 813, in run_migrations
webserver_1  |     self.get_context().run_migrations(**kw)
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/runtime/migration.py", line 549, in run_migrations
webserver_1  |     for step in self._migrations_fn(heads, self):
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/command.py", line 283, in upgrade
webserver_1  |     return script._upgrade_revs(revision, rev)
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/script/base.py", line 370, in _upgrade_revs
webserver_1  |     for script in reversed(list(revs))
webserver_1  |   File "/usr/local/lib/python3.7/contextlib.py", line 130, in __exit__
webserver_1  |     self.gen.throw(type, value, traceback)
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/script/base.py", line 203, in _catch_revision_errors
webserver_1  |     compat.raise_(util.CommandError(resolution), from_=re)
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/alembic/util/compat.py", line 296, in raise_
webserver_1  |     raise exception
webserver_1  | alembic.util.exc.CommandError: Can't locate revision identified by 'a13f7613ad25'

This error is currently causing us all sorts of frustrations with our Airflow deployment. We run airflow in docker and, oddly enough, this issue is happening for myself but not my coworkers, making it quite challenging to debug. We found alembic util command error can't find identifier however it is not super clear what we can do to resolve the error.

Scribe answered 22/8, 2021 at 1:44 Comment(1)
grep for 'a13f7613ad25' in alembic/versions/. Once you find it, you need to determine whether you should fix the issue by replacing the reference with another or by finding and restoring the lost a13f7613ad25.Salahi
D
16

You should wipe your database and recreate it from scratch (airflow db reset). Apparently the database you have have been corrupted - this could have happened if you used some development version of Arirflow or run some older version airflow 1.10 on Airflow 2 or the other way round.

I presume (since you are talking about co-worker's and your database - those are all development databases, so you should be able to reset them from scratch.

If this is a development database which uses sqlite, what can also help is to delete the sqlite3 file (you will find it in ${AIRFLOW_HOME} directory. This will drop the database and airflow will create one from scratch automatically when starting.

Dominick answered 22/8, 2021 at 9:50 Comment(3)
Thanks for this. We use docker-compose to spin up our postgres DB and we were able to resolve our issue with docker volume ls and then docker volume rm {VOLUME NAME} to remove the volume that was causing the issue.Scribe
Use airflow resetdb for Airflow 1.XOath
hello! this error happens to me when i deploy the worker on another server, I dont want to remove any volume because its the main one, any help?Haematoblast
C
1

if the volume was created via docker-compose , you should use docker-compose down --volumes

Cuenca answered 14/4, 2022 at 10:13 Comment(0)
S
0

I had to delete the pvc of postgresql of previous airflow helm install. After that i could install the new one.

Swath answered 19/4, 2023 at 12:28 Comment(0)
P
0

This can also happen when upgrading with Helm if you don't also update the container. This happened to me while upgrading from the community Airflow chart repository without specifying a version. It tried to run the db migrations up to the current chart's version of the container, but it pulls them from the Airflow container itself. I had the same container originally used to install it specified in the Values file.

Pannier answered 7/7, 2023 at 0:58 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Disreputable

© 2022 - 2024 — McMap. All rights reserved.