Alembic create_table, check if table exists

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' ()
+4
source share
2 answers

(, SQLAlchemy Alembic). alembic , , .

, , , , .

, "" , . autogenerate , .

0

, , . , psql drop table foo_model;

-3

All Articles