SQLAlchemy cannot find a class name SQLAlchemy cannot find a class name python python

SQLAlchemy cannot find a class name


This all turned out to be because of the way I've set SQLAlchemy up in Pyramid. Essentially you need to follow this section to the letter and make sure you use the same declarative_base instance as the base class for each model.

I was also not binding a database engine to my DBSession which doesn't bother you until you try to access table metadata, which happens when you use relationships.


if it's a subpackage class, add Item and Auction class to __init__.py in the subpackage.


The SQLAlchemy documentation on Importing all SQLAlchemy Models states in part:

However, due to the behavior of SQLAlchemy's "declarative" configuration mode, all modules which hold active SQLAlchemy models need to be imported before those models can successfully be used. So, if you use model classes with a declarative base, you need to figure out a way to get all your model modules imported to be able to use them in your application.

Once I imported all of the models (and relationships), the error about not finding the class name was resolved.

  • Note: My application does not use Pyramid, but the same principles apply.