Skip to content

Foreign key ondelete is ignored when creating key with inline_references #1820

Description

@deanmalan

Describe the bug

When using the inline_references parameter from #1780 to create a foreign key, the foreign key's ondelete parameter isn't respected.

Expected behavior

The following code

    op.add_column(
        "foo",
        sa.Column(
            "bar_id",
            sa.UUID(),
            sa.ForeignKey("bar.id", ondelete="SET NULL"),
            nullable=True,
        ),
        inline_references=True,
    )

emits

ALTER TABLE foo ADD COLUMN bar_id UUID REFERENCES bar (id);

instead of

ALTER TABLE foo ADD COLUMN bar_id UUID REFERENCES bar (id) ON DELETE SET NULL;

To Reproduce

    op.add_column(
        "foo",
        sa.Column(
            "bar_id",
            sa.UUID(),
            sa.ForeignKey("bar.id", ondelete="SET NULL"),
            nullable=True,
        ),
        inline_references=True,
    )

Versions.

  • OS: Debian GNU/Linux 13
  • Python: 3.13.9
  • Alembic: 1.18.4
  • SQLAlchemy: 2.0.49
  • Database: PostgreSQL 16
  • DBAPI:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions