Airflow: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set

I got this solution'ed. This happened because ab_* tables were not created at airflow initdb. All these tables are for Role-based-access-control – RBAC.

To have these tables, follow the instructions:

  1. edit airflow.cfg
[webserver]
rbac = True
  1. run airflow initdb to create these missing tables.

This solved my issue.


The most common cause for this in airflow 1.10.12 is to add a $AIRFLOW_HOME/webserver_config.py file that overrides the default.

If you are adding a webserver_config.py it must contain

SQLALCHEMY_DATABASE_URI = conf.get('core', 'SQL_ALCHEMY_CONN')

like in the default webserver_config.py.

In principle if you set rbac = True in airflow.cfg, remove webserver_config.py and execute any command like airflow list_users then airflow will create a webserver_config.py file for you with the proper SQLALCHEMY_DATABASE_URI = ... that you can modify afterwards.


The selected answer by @appleboy did not work for me, but the solution by @Nando_Quintana did.

Do the following to apply his fix as a patch

cd path/to/python/site-packages/airflow/www_rbac/
patch <<EOF
--- _app.py2019-09-25 17:18:59.127378849 +0000
+++ app.py 2019-09-25 17:18:53.467413221 +0000
@@ -53,6 +53,7 @@
     app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
     app.config['APP_NAME'] = app_name
     app.config['TESTING'] = testing
+    app.config['SQLALCHEMY_DATABASE_URI'] = conf.get('core', 'SQL_ALCHEMY_CONN')

     csrf.init_app(app)
EOF

Tested on Python 3.6.8 and Airflow 1.10.2


You could patch app.py in airflow source code:

Set SQLALCHEMY_DATABASE_URI in app.config from SQL_ALCHEMY_CONN just before database initialization db = SQLA(app).

This is the path to app.py file:

/Users/deepaksaroha/Desktop/apache_2.0/nb-atom-airflow/lib/python3.7/site-packages/airflow/www_rbac/app.py

And this is the line you should include:

app.config['SQLALCHEMY_DATABASE_URI'] = conf.get('core', 'SQL_ALCHEMY_CONN')