简体   繁体   English

气流操作错误 sqlalquemy (sqlite3.OperationalError)

[英]Airflow Operational error sqlalquemy (sqlite3.OperationalError)

I'm trying to install airflow, and I get this error when I try to create the db or run standalone.我正在尝试安装气流,当我尝试创建数据库或独立运行时出现此错误。 I tried to change the version of sqlalchemy but it didn't work.我试图更改 sqlalchemy 的版本,但没有奏效。

os: manjaro |操作系统:manjaro | sqlalchemy version: 1.4 | sqlalchemy 版本:1.4 | airflow version: 2.3.0气流版本:2.3.0

standalone | Starting Airflow Standalone
standalone | Checking database is initialized
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 13eb55f81627 -> 338e90f54d61, Add 
sqlite3.OperationalError: duplicate column name: operator

The above exception was the direct cause of the following exception:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) duplicate column name: operator
[SQL: ALTER TABLE task_instance ADD COLUMN operator VARCHAR(1000)]
(Background on this error at: http://sqlalche.me/e/14/e3q8)

Something to fix it?有什么可以解决的吗?

what I found I checked out the code files pointed out by 'Shi Chen' two files are responsible for this behavior.我发现我检查了“Shi Chen”指出的代码文件,两个文件是造成这种行为的原因。

33ae817a1ff4_add_kubernetes_resource_checkpointing.py
86770d1215c0_add_kubernetes_scheduler_uniqueness.py

Both the files are migration files using alembic and sqlalchemy libraries I found that following sqlalchemy code written in file 33ae817a1ff4_add_kubernetes_resource_checkpointing.py这两个文件都是使用 alembic 和 sqlalchemy 库的迁移文件,我发现以下 sqlalchemy 代码写入文件 33ae817a1ff4_add_kubernetes_resource_checkpointing.py

def upgrade():

    columns_and_constraints = [
        sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
        sa.Column("resource_version", sa.String(255))
    ]

    conn = op.get_bind()

    # alembic creates an invalid SQL for mssql dialect
    if conn.dialect.name not in ('mssql'):
        columns_and_constraints.append(sa.CheckConstraint("one_row_id", name="kube_resource_version_one_row_id"))

    table = op.create_table(
        RESOURCE_TABLE,
        *columns_and_constraints
    )

    op.bulk_insert(table, [
        {"resource_version": ""}
    ])

is interpreted into following SQL query which is not correct被解释为以下不正确的 SQL 查询

CREATE TABLE  kube_resource_version (one_row_id BOOL NOT NULL DEFAULT
true,  resource_version VARCHAR(255), PRIMARY KEY (one_row_id), 
CONSTRAINT kube_resource_version_one_row_id CHECK (one_row_id),  CHECK(one_row_id IN (0, 1))

Instead the SQL query should be some what like this相反,SQL 查询应该是这样的

CREATE TABLE  kube_resource_version (one_row_id BOOL NOT NULL DEFAULT
true,  resource_version VARCHAR(255), PRIMARY KEY (one_row_id), 
CONSTRAINT kube_resource_version_one_row_id CHECK (one_row_id IN (0, 1)))

The link provided by 'skadya' was helpful I got the system to work after making the changes in the code of the two above mentioned files. 'skadya' 提供的链接很有帮助,在对上述两个文件的代码进行更改后,我让系统正常工作。

you simple need to change the following code from您只需更改以下代码

if conn.dialect.name not in ('mssql'):
columns_and_constraints.append(
sa.CheckConstraint("one_row_id", name="kube_resource_version_one_row_id"))

to

if conn.dialect.name not in ('mssql', 'mysql'):
columns_and_constraints.append(
sa.CheckConstraint("one_row_id", name="kube_resource_version_one_row_id")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM