Skip to content
Advertisement

Is there other option to check if a table is in a SQl connection , Im trying to use dialect.has_table

from sqlalchemy import create_engine

from .conf import DB_CONNECTION_STR

conn = create_engine(DB_CONNECTION_STR)

def verify_table_exists(table_name):
    return conn.dialect.has_table(conn, table_name)

Im getting this error :

AttributeError: ‘Engine’ object has no attribute ‘exec_driver_sql’

Advertisement

Answer

Nowadays the preferred method for performing such reflection is to use inspect:

import sqlalchemy as sa

insp = sa.inspect(engine)
print(insp.has_table("team"))
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement