How to solve error "sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: session" when running Airflow

Viewed 1058

I've installed Apache Airflow version 2.2.4 on my system Ubuntu 20.0.4 LTS and I'm using these steps

  • export AIRFLOW_HOME=~/airflow
  • pip3 install apache-airflow
  • airflow db init
  • airflow users create --username admin --firstname XXXX --lastname XXX --role Admin --email XXX@gmail.com

When I'm running my server using this command

  • airflow webserver -p 8080

I've got an error saying

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: session

apacheAirflow

How can I solve this error?

3 Answers

Before running webserver using command airflow webserver, make sure to set AIRFLOW_HOME using below command:

 export AIRFLOW_HOME="your_airflow_directory"

For me the issue was that I have set the AIRFLOW_HOME on one tab of my terminal, but on the other tab (from where I was running the webserver) I forgot to set it. So the solution is to do the following in ALL TERMINAL TABS that you're using for Airflow:

  1. Activate the virtual environment where your Airflow is installed

    source your_airflow_venv/bin/activate
    
  2. Navigate to the directory where your Airflow project is

    cd /path_to_your_airflow_dir
    
  3. Update your AIRFLOW_HOME environment variable

    export AIRFLOW_HOME=$(pwd)
    
  4. Initialize the Airflow database

    airflow db init
    
  5. Start the Airflow Web Server or the Airflow Scheduler (depending on which terminal tab you currently are)

    airflow scheduler
    airflow webserver
    

I had the same error message. I made the mistake and naively installed airflow through pip.

I fixed the issue by deleting the directory AIRFLOW_HOME points to and reinstalling airflow through pip with a constraint. Then I initiated the automated airflow setup with the airflow standalone command.

Related