I have an alembic upgrade script that creates a table, however I do not want it to create a table if it already exists.
According to the alembic doc , I can pass the args keyword to op.create_tables, which are acceptable for sqlalchemy.schema.table , so I use the keyword keep_existing:
op.create_table('foo_model',
sa.Column('foo_id', sa.Integer(), nullable=False),
sa.Column('foo_str', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('foo_id'),
keep_existing= True
)
However, I still see that the table already exists.
sqlalchemy.exc.InternalError: (InternalError) (1050, u"Table 'foo_model' already exists") '\nCREATE TABLE foo_model (\n\tfoo_id INTEGER NOT NULL AUTO_INCREMENT, \n\tfoo_str VARCHAR(255), \n\tPRIMARY KEY (foo_id)\n)\n\n' ()
source
share