When I init a dag with a Variable param, it raises an Exception

Viewed 2540

I am using apache-airflow==1.10.0

I get errors that looks like this:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation "variable" does not exist
LINE 2: FROM variable

When I declare tasks like:

 from airflow.models import Variable
 dag = DAG('dag')
 PythonOperator('task_id', ratio=Variable.get('ratio'), dag=dag)

because I don't have a Variable table yet. I get errors that don't affect anything, but how can I prevent this from happening?

2 Answers

Run airflow upgradedb. It will create all the missing tables.

A workaround (in case airflow upgradedb doesn't work) is to do the following

  1. Remove all the calls to variables in your DAGs code, you can do this by putting all of them into a function set_variables() and commenting it out
  2. Start airflow webserver and create a dummy variable from the variable UI, this will create the Variable table
  3. Now you can uncomment your set_variables(), your programmatic calls to variables will now work since you have the Variable table
Related