SQLAlchemy: Engine object has no attribute _run_visitor

See original GitHub issue

Code:

@classmethod
@asyncio.coroutine
def connect(cls):
    cls.engine = yield from create_engine(host=config.MYSQL_HOST,
                                          port=config.MYSQL_PORT,
                                          user=config.MYSQL_USER,
                                          password=config.MYSQL_PASSWORD,
                                          db=config.MYSQL_DATABASE)

    yield from cls.create_tables()

@classmethod
@asyncio.coroutine
def create_tables(cls):
    cls.metadata = sa.MetaData()

    cls.friends = sa.Table('friends', cls.metadata,
                           sa.Column('user_id', sa.Integer),
                           sa.Column('friend_id', sa.Integer))

    cls.metadata.create_all(cls.engine)

cls.metadata.create_all() says:

AttributeError: 'Engine' object has no attribute '_run_visitor'

How can this be fixed?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
ghostcommented, Mar 10, 2017

@spiralman here’s what I did:

user_files = Table('user_files', meta_data,
                                Column('file_id', Integer, primary_key=True),
                                Column('file_name', String, nullable=False),
                                Column('file_data', LargeBinary, nullable=False),
                                Column('user_id', Integer, nullable=False)
                              )

        await connection.execute('''CREATE TABLE IF NOT EXISTS user_files (
                                    file_id SERIAL,
                                    file_name VARCHAR(50) NOT NULL,
                                    file_data BYTEA NOT NULL,
                                    user_id INTEGER NOT NULL
                                  )''')
7reactions
BjoernSchcommented, May 18, 2017

That´s not a solution as I don´t want to write the SQL. Creating single tables by running await MyTable.__table__.create(engine) doesn´t work either.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQLAlchemy AttributeError: 'AsyncEngine' object has no ...
Replace: Base.metadata.create_all(engine). with this: async def init_models(): async with engine.begin() as conn: await ...
Read more >
Working with Engines and Connections — SQLAlchemy 2.0 ...
This section details direct usage of the Engine , Connection , and related objects. Its important to note that when using the SQLAlchemy...
Read more >
Working with Engines and Connections — SQLAlchemy 1.3 ...
This section describes how to use transactions when working directly with Engine and Connection objects. When using the SQLAlchemy ORM, the public API...
Read more >
Describing Databases with MetaData
MetaData is a container object that keeps together many different features of a database (or multiple databases) being described.
Read more >
Working with Engines and Connections
This section describes how to use transactions when working directly with Engine and Connection objects. When using the SQLAlchemy ORM, the public API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found