0

Hi I added a new model to SQLAlchemy models. But this change trigers this error on all alembic commands

Alembic TypeError: Additional arguments should be named <dialectname>_<argument>, got 'nullable'

My table looks like this:

class XClass(Base):
    __tablename__ = "x_table_name"

    X1 = Column(
        String, ForeignKey("y_table.COLUMN", deferrable=True, initially="DEFERRED"),
        primary_key=True,
        nullable=False
    )
    X2 = Column(String, nullable=False)
    PROBLEMATIC_COLUMN = Column(
        String, ForeignKey("table_a.Y3", deferrable=True, initially="DEFERRED",
                           nullable=True,
                           unique=True)
    )
    X3 = Column(String, nullable=False)
    X4 = Column(String, nullable=False)
    X% = Column(String, nullable=False)

    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)

Model from table_a in the PROBLEMATIC_COLUMN looks like this:

class TableA(Base):
    __tablename__ = "table_a"

    Y1 = Column(
        String,
        ForeignKey("table_b.Z1", deferrable=True, initially="DEFERRED"),
        primary_key=True,
    )
    Y2 = Column(String, primary_key=True)
    Y3 = Column(String, primary_key=True)

    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)

When change PROBLEMATIC_COLUMNT in XClass to:

PROBLEMATIC_COLUMN = Column(String, nullable=False)

Alembic works corectly.

Any one knows what im doin wrong?

Michal
  • 112
  • 1
  • 9
  • `Column(String, ForeignKey("table_a.Y3", deferrable=True, initially="DEFERRED", nullable=True, unique=True))` - deferrable, nullable and unique should be in the column definition, _not_ the `ForeignKey` definition. You probably want `Column(String, ForeignKey("table_a.Y3"), deferrable=True, initially="DEFERRED", nullable=True, unique=True)` – snakecharmerb Oct 29 '22 at 10:29
  • Thanks, but it hasn't helped. Now I'm getting TypeError: Additional arguments should be named _, got 'deferrable' – Michal Oct 29 '22 at 12:36

0 Answers0