@@ -341,7 +341,7 @@ class SimpleItems(Base):
341341
342342 id: Mapped[int] = mapped_column(Integer, primary_key=True)
343343 top_container_id: Mapped[int] = \
344- mapped_column(ForeignKey('simple_containers.id'))
344+ mapped_column(ForeignKey('simple_containers.id'), nullable=False )
345345 parent_container_id: Mapped[Optional[int]] = \
346346 mapped_column(ForeignKey('simple_containers.id'))
347347
@@ -812,6 +812,34 @@ class SimpleItems(Base):
812812 )
813813
814814
815+ def test_composite_nullable_pk (generator : CodeGenerator ) -> None :
816+ Table (
817+ "simple_items" ,
818+ generator .metadata ,
819+ Column ("id1" , INTEGER , primary_key = True ),
820+ Column ("id2" , INTEGER , primary_key = True , nullable = True ),
821+ )
822+ validate_code (
823+ generator .generate (),
824+ """\
825+ from typing import Optional
826+
827+ from sqlalchemy import Integer
828+ from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
829+
830+ class Base(DeclarativeBase):
831+ pass
832+
833+
834+ class SimpleItems(Base):
835+ __tablename__ = 'simple_items'
836+
837+ id1: Mapped[int] = mapped_column(Integer, primary_key=True)
838+ id2: Mapped[Optional[int]] = mapped_column(Integer, primary_key=True, nullable=True)
839+ """ ,
840+ )
841+
842+
815843def test_joined_inheritance (generator : CodeGenerator ) -> None :
816844 Table (
817845 "simple_sub_items" ,
@@ -1045,7 +1073,7 @@ class Group(Base):
10451073 )
10461074
10471075 groups_id: Mapped[int] = mapped_column(Integer, primary_key=True)
1048- group_name: Mapped[str] = mapped_column(Text(50))
1076+ group_name: Mapped[str] = mapped_column(Text(50), nullable=False )
10491077
10501078 users: Mapped[list['User']] = relationship('User', back_populates='group')
10511079
@@ -1590,7 +1618,7 @@ class WithItems(Base):
15901618 __tablename__ = 'with_items'
15911619
15921620 id: Mapped[int] = mapped_column(Integer, primary_key=True)
1593- int_items_not_optional: Mapped[list[int]] = mapped_column(ARRAY(INTEGER()))
1621+ int_items_not_optional: Mapped[list[int]] = mapped_column(ARRAY(INTEGER()), nullable=False )
15941622 str_matrix: Mapped[Optional[list[list[str]]]] = mapped_column(ARRAY(VARCHAR(), dimensions=2))
15951623""" ,
15961624 )
0 commit comments