Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6628739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:09:37+00:00 2026-05-25T22:09:37+00:00

I am trying to create a program that loads in over 100 tables from

  • 0

I am trying to create a program that loads in over 100 tables from a database so that I can change all appearances of a user’s user id.

Rather than map all of the tables individually, I decided to use a loop to map each of the tables using an array of objects. This way, the table definitions can be stored in a config file and later updated.

Here is my code so far:

def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    meta.Session.configure(bind=engine)
    meta.engine = engine

class Table:
    tableID = ''
    primaryKey = ''
    pkType = sa.types.String()
    class mappedClass(object):
        pass


WIW_TBL = Table()
LOCATIONS_TBL = Table()

WIW_TBL.tableID = "wiw_tbl" 
WIW_TBL.primaryKey = "PORTAL_USERID"
WIW_TBL.pkType = sa.types.String()

LOCATIONS_TBL.tableID = "locations_tbl"
LOCATIONS_TBL.primaryKey = "LOCATION_CODE"
LOCATIONS_TBL.pkType = sa.types.Integer()

tableList = ([WIW_TBL, LOCATIONS_TBL])

for i in tableList:

    i.tableID = sa.Table(i.tableID.upper(), meta.metadata,
    sa.Column(i.primaryKey, i.pkType, primary_key=True),
    autoload=True,
    autoload_with=engine) 

    orm.mapper(i.mappedClass, i.tableID)

The error that this code returns is:

sqlalchemy.exc.ArgumentError: Class '<class 'changeofname.model.mappedClass'>' already has a primary mapper defined. Use non_primary=True to create a non primary Mapper.  clear_mappers() will remove *all* current mappers from all classes.

I cant use clear_mappers as it wipes all of the classes and the entity_name scheme doesn’t seem to apply here.

It seems that every object wants to use the same class, although they all should have their own instance of it.

Does anyone have any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:09:38+00:00Added an answer on May 25, 2026 at 10:09 pm

    Well, in your case it *is the same Class you try to map to different Tables. To solve this, create a class dynamically for each Table:

    class Table(object):
        tableID = ''
        primaryKey = ''
        pkType = sa.types.String()
        def __init__(self):
            self.mappedClass = type('TempClass', (object,), {})
    

    But I would prefer slightly cleaner version:

    class Table2(object):
        def __init__(self, table_id, pk_name, pk_type):
            self.tableID = table_id
            self.primaryKey = pk_name
            self.pkType = pk_type
            self.mappedClass = type('Class_' + self.tableID, (object,), {})
    # ...
    WIW_TBL = Table2("wiw_tbl", "PORTAL_USERID", sa.types.String())
    LOCATIONS_TBL = Table2("locations_tbl", "LOCATION_CODE", sa.types.Integer())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to create a bridge program in twisted.web that receives data from a
I'm trying to create a windows form application that manipulates data from several tables
I'm trying to create a program that takes a text file of c++ code
I am trying to create a program that will do some simple calculations, but
I'm currently trying to create a program that estimates location based on signal strength.
I have been trying to create a Ruby program that will be running online
Alright so what I am trying to do is essentially create a program that,
I'm trying to create a C dynamic library that's callable from Java. I've compiled
I am trying to create a Multi-Language WPF program that will load it's languages
I'm trying to create a program that checks if someone is going to Happy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.