Skip to content

The SQL model cannot perform insertion into another table using queried data #1019

Description

@writebai2

Issue Content

The SQL model cannot insert the queried data into the corresponding table of another database

engine = create_engine(str(settings.MYSQL_DATABASE_URL))
rds_engine = create_engine(str(settings.RDS_DATABASE_URI), echo=True)

def get_online_products():
    statement = (
        select(
            Tbl_Product
        )
        .limit(1)
    )

    with Session(engine) as session:
        products = session.exec(statement).all()
    return products

def insert_main():
    product_datas = get_online_products()
    with Session(rds_engine) as session:
        session.add_all(product_datas)
        session.commit()

if __name__ == "__main__":
    insert_main()

After execution:
PS D:\python\db_visualization> D:\python\myvenv\Scripts\python.exe "d:\python\db_visualization\back_main.py"

There is no response in the table after execution

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions