Home > front end >  Something wrong with database initialized by Airflow
Something wrong with database initialized by Airflow

Time:09-03

I'm trying to work with Apache Airflow. When I started my first DAG, it fails (the very first task fails). When I try to check logs, they are not displayed properly in the GUI and I get the exception 'airflow.models.taskinstance.TaskInstance object' has no attribute 'map_index'. I checked the database and found, that table TaskInstance really hasn't such a column.

I created a Postgres database named airflow and airflow user, and initialized the database with the airflow init db command. I've done everything following the instruction.

So it looks like the schemas of tables in the airflow database are not exactly the same as the airflow scheduler expects.

I installed airflow with the command sudo python3 -m pip install apache-airflow[postgres,s3,aws,azure,gcp,slack], which installed the newest stable version of airflow: 2.3.4. And it seems like airflow and airflow-postgres-special dependencies are of the same version.

CodePudding user response:

You likely installed the db using older version of Airflow and never run upgrade after you moved to 2.3.4. It's very likely that the CLI command you have is for (whatever reason) using another airflow version - and simply you have initialized the db to an old version.

You should always run airflow db upgrade after an upgrade (generally you ar safe to re-run it any time so you can do it now) - see https://airflow.apache.org/docs/apache-airflow/stable/installation/upgrading.html

But you have to make sure you have no problem with different versions of airlfow available for CLI and for actual execution of schedulers/workers etc.

Also 2.3.* version of Airflow has some useful tools that allow you to inspect the state of your db airflow db commands are expended, and you will be able to see which migrations you locally have, which of them are applied and even it will allow you to migrate back and forth between different versions.

See https://airflow.apache.org/docs/apache-airflow/stable/migrations-ref.html and https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#db

You need to get familiar with those if you have problems with your DB.

  • Related