Skip to content

Function add_column doesn't work for primary_key #1232

Description

@BoWuGit

Describe the bug
I had a table which didn't has primary_key previously, and later I wanted to add a primary_key column, so I used add_column function as follows, but the primary_key was not added. Thanks for your attention.

op.add_column("collection1", sa.Column("id", sa.String, primary_key=True))

To Reproduce
A minimal example is as follows:

"""interaction test

Revision ID: 3143332ab75e
Revises: 63e25a7c5c04
Create Date: 2023-04-27 09:48:23.650748

"""
from alembic import op
import sqlalchemy as sa

revision = '3143332ab75e'
down_revision = '63e25a7c5c04'
branch_labels = None
depends_on = None

def upgrade():
    op.create_table(
        "collection1",
        sa.Column("status", sa.Integer, nullable=False, server_default="1"),
        sa.Column("created_at", sa.Integer, server_default=sa.text("extract(epoch from now())::int")),
        sa.Column("updated_at", sa.Integer, server_default=sa.text("extract(epoch from now())::int")),
        sa.Column("deleted_at", sa.Integer, server_default=sa.text("0")),
    )
    op.add_column("collection1", sa.Column("id", sa.String, primary_key=True))


def downgrade():
    op.drop_table("collection1")

Versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    use casenot quite a feature and not quite a bug, something we just didn't think of

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions