0

I'm using replit. and in the console, I ran the following command:

pip install sqlalchemy

Then, in the main.py file:

from sqlalchemy import create_engine
engine = create_engine('sqlite:///census_nyc.sqlite')
connection = engine.connect()
print(engine.table_names())

the error I get is as follows:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    print(engine.table_names())
AttributeError: 'Engine' object has no attribute 'table_names'

I'm trying to follow datacamp's introduction to relational databases and I've fallen at the first hurdle.

I tried the above code exactly as presented in the training videos but it doesn't work.

Luke
  • 1
  • 1
  • See https://stackoverflow.com/questions/6473925/sqlalchemy-getting-a-list-of-tables if you want to list tables. See https://docs.sqlalchemy.org/en/20/core/connections.html#basic-usage for the sqlalchemy documentation and introduction. If you want commentary on a specific tutorial you are following then link to it; I seems the `table_names` method was removed several versions ago. – Pete Kirkham Apr 25 '23 at 10:30

1 Answers1

0

The engine.table_names() function is deprecated since version 1.4: https://docs.sqlalchemy.org/en/14/core/connections.html#sqlalchemy.engine.Engine.table_names

You can use the inspect() function for runtime information on any SQLAlchemy objects, including the engine. This creates an inspection object which can be queried for more information.

For your need:

from sqlalchemy import create_engine, inspect
engine = create_engine('sqlite:///census_nyc.sqlite')
inspection = inspect(engine)
inspection.get_tables_names()

More info on the inspection API: https://docs.sqlalchemy.org/en/20/core/inspection.html#sqlalchemy.inspect