Mapper could not collect primary key columns

enter image description here

I created a tmp table from the sqllite table which is a subset of the original table based on various selection criteria. A sample is in the screenshot.

I am trying to loop through the table records one at a time to update the field in each. I have:

source_table= self.source
engine = create_engine(db_path)
Base = declarative_base()
# metadata = Base.metadata
# Look up the existing tables from database
Base.metadata.reflect(engine)

# Create class that maps via ORM to the database table
table = type(source_table, (Base,), {'__tablename__': source_table})

Session = sessionmaker(bind=engine)
session = Session()
i = 0
for row in session.query(table).limit(500):

    i += 1
    print object_as_dict(row)

      

But this gives:

ArgumentError: Mapper Mapper|tmp|tmp could not assemble any primary key columns for mapped table 'tmp'

      

How can I accomplish this loop?

+3


source to share





All Articles