From 8396483882a5beed915f2560325721934f58a37c Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 19 Dec 2022 21:09:36 +0100 Subject: output error when DROP COLUMN fails In case it might be caused by something else than SQLite's inability to delete a column, it's good to have the actual error written out somewhere. --- fietsboek/alembic/versions/20221214_c939800af428.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fietsboek/alembic/versions/20221214_c939800af428.py b/fietsboek/alembic/versions/20221214_c939800af428.py index 79ec899..4b07983 100644 --- a/fietsboek/alembic/versions/20221214_c939800af428.py +++ b/fietsboek/alembic/versions/20221214_c939800af428.py @@ -20,14 +20,15 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### try: op.drop_column('tracks', 'gpx') - except sa.exc.OperationalError: + except sa.exc.OperationalError as exc: # sqlite < 3.35.0 does not know "ALTER TABLE DROP COLUMN", in which # case we probably don't want to break the DB. Instead, we simply # "drop" the column by setting it empty, which should still help in # saving some space. logging.getLogger(__name__).warning( "Your database does not support dropping a column. " - "We're setting the content to zero instead." + "We're setting the content to zero instead (%s).", + exc, ) op.execute("UPDATE tracks SET gpx = '';") # ### end Alembic commands ### @@ -36,6 +37,9 @@ def downgrade(): # ### commands auto generated by Alembic - please adjust! ### try: op.add_column('tracks', sa.Column('gpx', sa.BLOB(), nullable=True)) - except sa.exc.OperationalError: - logging.getLogger(__name__).warning("The column already exists.") + except sa.exc.OperationalError as exc: + logging.getLogger(__name__).warning( + "The column already exists - doing nothing (%s).", + exc, + ) # ### end Alembic commands ### -- cgit v1.2.3