1. Michael Bayer
  2. sqlalchemy

Issues

Issue #3023 resolved

inconsistent behavior of nullable with PrimaryKeyConstraint

Michael Bayer
repo owner created an issue

this is fairly egregious, breaks alembic as one might expect

from sqlalchemy import *

m = MetaData()

t1 = Table('t1', m, Column('x', Integer), PrimaryKeyConstraint('x'))

t2 = Table('t2', m, Column('x', Integer, primary_key=True))

assert list(t1.primary_key) == [t1.c.x]

assert list(t2.primary_key) == [t2.c.x]

assert t1.c.x.primary_key
assert t2.c.x.primary_key

assert not t2.c.x.nullable
assert not t1.c.x.nullable

Comments (3)

  1. Michael Bayer reporter
    • The :paramref:.Column.nullable flag is implicitly set to False when that :class:.Column is referred to in an explicit :class:.PrimaryKeyConstraint for that table. This behavior now matches that of when the :class:.Column itself has the :paramref:.Column.primary_key flag set to True, which is intended to be an exactly equivalent case. fixes #3023

    → <<cset bd56485f4c15>>

  2. Michael Bayer reporter
    • The :paramref:.Column.nullable flag is implicitly set to False when that :class:.Column is referred to in an explicit :class:.PrimaryKeyConstraint for that table. This behavior now matches that of when the :class:.Column itself has the :paramref:.Column.primary_key flag set to True, which is intended to be an exactly equivalent case. fixes #3023

    → <<cset ca99fca50d2c>>

  3. Log in to comment