# Buggy code
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column("bill", sa.Column("converted_amount", sa.Float(), nullable=True))
    op.add_column(
        "bill",
        sa.Column(
            "original_currency",
            sa.String(length=3),
            server_default=CurrencyConverter.default,
            nullable=True,
        ),
    )
    op.add_column(
        "bill_version",
        sa.Column("converted_amount", sa.Float(), autoincrement=False, nullable=True),
    )
    op.add_column(
        "bill_version",
        sa.Column(
            "original_currency", sa.String(length=3), autoincrement=False, nullable=True
        ),
    )
    op.add_column(
        "project",
        sa.Column(
            "default_currency",
            sa.String(length=3),
            server_default=CurrencyConverter.default,
            nullable=True,
        ),
    )
    op.add_column(
        "project_version",
        sa.Column(
            "default_currency", sa.String(length=3), autoincrement=False, nullable=True
        ),
    )
    # ### end Alembic commands ###
    op.execute(
        """
    UPDATE bill
    SET converted_amount = amount
    WHERE converted_amount IS NULL
    """
    )


# Traceback (sqlalchemy.exc.DataError)
INFO  [alembic.runtime.migration] Running upgrade cb038f79982e -> 927ed575acbd, Add currencies
Traceback (most recent call last):
File "/home/zorun/tmp/venv3-ihatemoney/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1247, in _execute_context
self.dialect.do_execute(
File "/home/zorun/tmp/venv3-ihatemoney/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(3)

The above exception was the direct cause of the following exception:

sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation) value too long for type character varying(3)

[SQL: ALTER TABLE bill ADD COLUMN original_currency VARCHAR(3) DEFAULT 'No Currency']

# Fixed code
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column("bill", sa.Column("converted_amount", sa.Float(), nullable=True))
    op.add_column(
        "bill",
        sa.Column(
            "original_currency",
            sa.String(length=3),
            server_default=CurrencyConverter.no_currency,
            nullable=True,
        ),
    )
    op.add_column(
        "bill_version",
        sa.Column("converted_amount", sa.Float(), autoincrement=False, nullable=True),
    )
    op.add_column(
        "bill_version",
        sa.Column(
            "original_currency", sa.String(length=3), autoincrement=False, nullable=True
        ),
    )
    op.add_column(
        "project",
        sa.Column(
            "default_currency",
            sa.String(length=3),
            server_default=CurrencyConverter.no_currency,
            nullable=True,
        ),
    )
    op.add_column(
        "project_version",
        sa.Column(
            "default_currency", sa.String(length=3), autoincrement=False, nullable=True
        ),
    )
    # ### end Alembic commands ###
    op.execute(
        """
    UPDATE bill
    SET converted_amount = amount
    WHERE converted_amount IS NULL
    """
    )