首页 > 解决方案 > 气流 - SQL Server 连接

问题描述

我有一个关于将后端连接从 SQLite 更改为 SQL Server 的问题。在为 传递正确的连接字符串后sql_alchemy_conn,我运行以下命令airflow initdb:我收到以下错误:

sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]一张表只能有一个时间戳列。因为表'task_reschedule'已经有一个,不能添加列'start_date'。 (2738) (SQLExecDirectW)") [SQL: '\nCREATE TABLE task_reschedule (\n\tid INTEGER NOT NULL IDENTITY(1,1), \n\ttask_id VARCHAR(250) ) NOT NULL,\n\tdag_id VARCHAR(250) NOT NULL,\n\texecution_date TIMESTAMP NOT NULL,\n\ttry_number INTEGER NOT NULL,\n\tstart_date TIMESTAMP NOT NULL,\n\tend_date TIMESTAMP NOT NULL,\n\ tduration INTEGER NOT NULL, \n\treschedule_date TIMESTAMP NOT NULL, \n\tPRIMARY KEY (id), \n\tCONSTRAINT task_reschedule_dag_task_date_fkey FOREIGN KEY(task_id, dag_id, execution_date) REFERENCES task_instance (task_id, dag_id,execution_date)\n)\n\n'](此错误的背景:http://sqlalche.me/e/f405 )

标签: airflow

解决方案


所以这对我有用:在文件中:0a2a5b66e19d_add_task_reschedule_table.py添加:

def mysql_datetime():
    return mysql.DATETIME(timezone=True)

并替换任何具有timestamp()以下内容的行:

sa.Column('execution_date', timestamp(), nullable=False, server_default=None),

有了这个:

sa.Column('execution_date', mysql_datetime(), nullable=False, server_default=None),

进行此更改后,上述错误就会消失,但我不确定是否还有其他意外后果。如果是这样,我将在此处更新或仅使用 MySQL 数据库。


推荐阅读