AirFlow初始化的时候遇到 Global variable explicit_defaults_for_timestamp needs to be on (1) for mysql
在安装airflow后,初始化遇到这样的问题
Traceback (most recent call last): File "/opt/anaconda3/bin/airflow", line 32, in <module> args.func(args) File "/opt/anaconda3/lib/python3.7/site-packages/airflow/bin/cli.py", line 1102, in initdb db.initdb(settings.RBAC) File "/opt/anaconda3/lib/python3.7/site-packages/airflow/utils/db.py", line 106, in initdb upgradedb() File "/opt/anaconda3/lib/python3.7/site-packages/airflow/utils/db.py", line 377, in upgradedb command.upgrade(config, 'heads') File "/opt/anaconda3/lib/python3.7/site-packages/alembic/command.py", line 298, in upgrade script.run_env() File "/opt/anaconda3/lib/python3.7/site-packages/alembic/script/base.py", line 489, in run_env util.load_python_file(self.dir, "env.py") File "/opt/anaconda3/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file module = load_module_py(module_id, path) File "/opt/anaconda3/lib/python3.7/site-packages/alembic/util/compat.py", line 173, in load_module_py spec.loader.exec_module(module) File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/opt/anaconda3/lib/python3.7/site-packages/airflow/migrations/env.py", line 92, in <module> run_migrations_online() File "/opt/anaconda3/lib/python3.7/site-packages/airflow/migrations/env.py", line 86, in run_migrations_online context.run_migrations() File "<string>", line 8, in run_migrations File "/opt/anaconda3/lib/python3.7/site-packages/alembic/runtime/environment.py", line 846, in run_migrations self.get_context().run_migrations(**kw) File "/opt/anaconda3/lib/python3.7/site-packages/alembic/runtime/migration.py", line 518, in run_migrations step.migration_fn(**kw) File "/opt/anaconda3/lib/python3.7/site-packages/airflow/migrations/versions/0e2a74e0fc9f_add_time_zone_awareness.py", line 45, in upgrade "Global variable explicit_defaults_for_timestamp needs to be on (1) for mysql" Exception: Global variable explicit_defaults_for_timestamp needs to be on (1) for mysql
解决方法:
进入mysql airflow 数据库,设置global explicit_defaults_for_timestamp
mysql> show global variables like '%timestamp%'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | explicit_defaults_for_timestamp | OFF | | log_timestamps | UTC | +---------------------------------+-------+ 2 rows in set (0.00 sec) mysql> set global explicit_defaults_for_timestamp =1; Query OK, 0 rows affected (0.00 sec) mysql>