I want to create a new table with my alembic migration file and add 2 records on the table. My upgrade()
function
def upgrade():
op.create_table(
'new_table',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('text', sa.String(length=180), nullable=False),
sa.PrimaryKeyConstraint('id', name='pk_new_table'),
sa.UniqueConstraint('text', name='uq_new_table__text'),
)
# Create ad-hoc table as a helper
new_table = sa.table(
'new_table',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('text', sa.String(length=180), nullable=False),
sa.PrimaryKeyConstraint('id', name='pk_new_table'),
sa.UniqueConstraint('text', name='uq_new_table__text'),
)
op.bulk_insert(new_table, [
{'text': 'First'},
{'text': 'Second'}
])
When running the upgrade through alembic I get the following error
AttributeError: 'PrimaryKeyConstraint' object has no attribute 'key'
This error begins from the line that contains the sa.UniqueConstraint('text', name='uq_new_table__text'),
on the SqlAlchemy table. What could be wrong?
Database backend on which the migration is applied is MySQL server.