Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function add_column doesn't work for primary_key #1232

Closed
BoWuGit opened this issue Apr 29, 2023 · 2 comments
Closed

Function add_column doesn't work for primary_key #1232

BoWuGit opened this issue Apr 29, 2023 · 2 comments

Comments

@BoWuGit
Copy link

BoWuGit commented Apr 29, 2023

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.

@BoWuGit BoWuGit added the requires triage New issue that requires categorization label Apr 29, 2023
@zzzeek zzzeek added documentation expected behavior and removed requires triage New issue that requires categorization labels Apr 29, 2023
@zzzeek
Copy link
Member

zzzeek commented Apr 29, 2023

I will add a note to the documentation now. constraints such as primary key or check constraints can only be added using constraint directives such as op.create_primary_key()

@BoWuGit
Copy link
Author

BoWuGit commented Apr 30, 2023

OK, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants