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 8390869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:06:56+00:00 2026-06-09T19:06:56+00:00

I would like to modify some database data as part of an alembic upgrade.

  • 0

I would like to modify some database data as part of an alembic upgrade.

I thought I could just add any code in the upgrade of my migration, but the following fails:

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('smsdelivery', sa.Column('sms_message_part_id', sa.Integer(), sa.ForeignKey('smsmessagepart.id'), nullable=True))
    ### end Alembic commands ###

    from volunteer.models import DBSession, SmsDelivery, SmsMessagePart

    for sms_delivery in DBSession.query(SmsDelivery).all():
        message_part = DBSession.query(SmsMessagePart).filter(SmsMessagePart.message_id == sms_delivery.message_id).first()
        if message_part is not None:
            sms_delivery.sms_message_part = message_part

with the following error:

sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on mapper Mapper|SmsDelivery|smsdelivery, SQL expression or this Session

I am not really understanding this error. How can I fix this or is doing operations like this not a possibility?

  • 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-06-09T19:06:57+00:00Added an answer on June 9, 2026 at 7:06 pm

    It is difficult to understand what exactly you are trying to achieve from the code excerpt your provided. But I’ll try to guess. So the following answer will be based on my guess.

    Line 4 – you import things (DBSession, SmsDelivery, SmsMessagePart) form your modules and then you are trying to operate with these objects like you do in your application.

    The error shows that SmsDelivery is a mapper object – so it is pointing to some table. mapper objects should bind to valid sqlalchemy connection.

    Which tells me that you skipped initialization of DB objects (connection and binding this connection to mapper objects) like you normally do in your application code.

    DBSession looks like SQLAlchemy session object – it should have connection bind too.

    Alembic already has connection ready and open – for making changes to db schema you are requesting with op.* methods.

    So there should be way to get this connection.

    According to Alembic manual op.get_bind() will return current Connection bind:
    For full interaction with a connected database, use the “bind” available from the context:

    from alembic import op
    connection = op.get_bind()
    

    So you may use this connection to run your queries into db.

    PS. I would assume you wanted to perform some modifications to data in your table. You may try to formulate this modification into one update query. Alembic has special method for executing such changes – so you would not need to deal with connection.
    alembic.operations.Operations.execute

    execute(sql, execution_options=None)
    

    Execute the given SQL using the current migration context.

    In a SQL script context, the statement is emitted directly to the output stream. There is no return result, however, as this function is oriented towards generating a change script that can run in “offline” mode.

    Parameters: sql – Any legal SQLAlchemy expression, including:

    • a string a sqlalchemy.sql.expression.text() construct.
    • a sqlalchemy.sql.expression.insert() construct.
    • a sqlalchemy.sql.expression.update(),
    • sqlalchemy.sql.expression.insert(), or
    • sqlalchemy.sql.expression.delete() construct. Pretty much anything
      that’s “executable” as described in SQL Expression Language Tutorial.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code, similar to the following, that I would like to modify: Sub
I would like to store some Application-Related Metadata for Files, and NTFS Alternate Data
I would like modify HTML like I am <b>Sadi, novice</b> programmer. to I am
I would like to modify an object private variable class Example(): __myTest1 = 1
We have a customer that would like to modify application user messages that we
I'm absolutely new to JavaScript and would like to modify a textarea of a
I'm using HighLine to write my console application and I would like to modify
I would like to select a node and modify its attributes and child-nodes using
I would like to load a HTML document and modify it's text in PHP.
I would like to retrieve the contents of a file, filter and modify them

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.