4

When I use the create_view () method of the sqlalchemy-utils module, everything works just fine the first time I run my script. However, every time after that first call, I encounter this error :

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) table XXX already exists.

I am currently capturing the exception and pass to avoid my script to stop but this seems messy to me.

Is there a way to avoid that behavior ?

  • There is SQLAlchemy.inspect().get_table_names(), which gives you a list of - surprise - table names. You could then check if the table you want to create is already in there. However, the try:except-method you mentioned is perfectly valid, cleaner and less expensive. – joppich Nov 21 '18 at 10:40

0 Answers0