You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行airflow db reset无法删除表,运行airflow db init报错

解决Airflow db init报错:table _alembic_tmp_dag_run already exists

问题场景

未修改任何环境配置的情况下,运行airflow db init时触发如下报错,怀疑依赖损坏:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) table _alembic_tmp_dag_run already exists
[SQL: 
CREATE TABLE _alembic_tmp_dag_run (
        id INTEGER NOT NULL, 
        dag_id VARCHAR(250), 
        execution_date DATETIME, 
        state VARCHAR(50), 
        run_id VARCHAR(250), 
        external_trigger BOOLEAN, 
        conf BLOB, 
        end_date DATETIME, 
        start_date DATETIME, 
        run_type VARCHAR(50) NOT NULL, 
        PRIMARY KEY (id), 
        UNIQUE (dag_id, run_id), 
        UNIQUE (dag_id, execution_date)
)

]

当前使用的依赖版本:

apache-airflow                      2.3.3
apache-airflow-client               2.3.0
apache-airflow-providers-common-sql 1.4.0
apache-airflow-providers-ftp        3.3.1
apache-airflow-providers-http       4.3.0
apache-airflow-providers-imap       3.1.1
apache-airflow-providers-sqlite     3.3.2

解决方案

1. 手动清理残留临时表

该错误大概率是之前的数据库操作中断,导致Alembic的临时表未被自动清理。直接删除临时表即可:

  • 找到Airflow默认SQLite数据库路径:~/airflow/airflow.db
  • 打开SQLite命令行:
    sqlite3 ~/airflow/airflow.db
    
  • 执行删除命令:
    DROP TABLE IF EXISTS _alembic_tmp_dag_run;
    
  • 退出命令行:.quit
  • 重新运行airflow db init

2. 重置数据库(数据会丢失)

如果清理临时表无效,直接重置数据库:

# 先停止所有Airflow服务
airflow db reset --yes
airflow db init

3. 统一Airflow版本

注意到apache-airflow和apache-airflow-client版本不一致(2.3.3 vs 2.3.0),版本不兼容也可能引发异常,建议统一版本:

pip install apache-airflow-client==2.3.3

内容的提问来源于stack exchange,提问作者C. Claudio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 12:37:20