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

  • Home
  • SEARCH
  • 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 4272856
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:38:03+00:00 2026-05-21T07:38:03+00:00

When I insert into MySQL with SQLAlchemy, I see the message ROLLBACK appear in

  • 0

When I insert into MySQL with SQLAlchemy, I see the message “ROLLBACK” appear in the outputed log for the development server. How can I tell why the rollback is happening?

2011-04-10 00:35:32,736 INFO  [sqlalchemy.engine.base.Engine.0x...4710][MainThread] INSERT INTO pageview (time, unit_id, visitor_id, url_id, referrer_id, reservation_id, visit_id) VALUES (%s, %s, %s, %s, %s, %s, %s)
2011-04-10 00:35:32,736 INFO  [sqlalchemy.engine.base.Engine.0x...4710][MainThread] (datetime.datetime(2011, 1, 31, 0, 1, 53), 120L, 5538L, 11075L, 11076L, 5538L, None) 
2011-04-10 00:35:32,737 INFO  [sqlalchemy.engine.base.Engine.0x...4710][MainThread] ROLLBACK 
Starting server in PID 10158. 
serving on 0.0.0.0:6543 view at http://127.0.0.1:6543

I am noticing that the letter “L” appears after every foreign key value (ex: the unit_id field is “120L” instead of “120”). Could that be related to this issue?

Here is the python code that is doing the insert:

@classmethod
def unconverted(class_):
    session = DBSession()
    return session.query(class_).filter(class_.pageview == None).order_by(class_.time).limit(5).all()

@classmethod
def convert_all(class_):
    session = DBSession()

    unconverted = class_.unconverted()
    for item in unconverted:

        pageview = PageView(raw_request=item)
        item.pageview = pageview
        session.add(item)

    session.flush()
    transaction.commit()
    session.close()

EDIT:

Following the advice of plaes, I get the following exception when doing a try/except on session.flush():

2011-04-10 11:33:44,462 INFO  [sqlalchemy.engine.base.Engine.0x...3750][MainThread] ROLLBACK
(IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`metrics`.`pageview`, CONSTRAINT `pageview_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `unit` (`id`))') 'INSERT INTO pageview (time, unit_id, visitor_id, url_id, referrer_id, reservation_id, visit_id) VALUES (%s, %s, %s, %s, %s, %s, %s)' (datetime.datetime(2011, 1, 31, 0, 1, 53), 120L, 5608L, 11215L, 11216L, 5608L, None)

What is this error occurring?

  • 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-21T07:38:04+00:00Added an answer on May 21, 2026 at 7:38 am

    You can always print out the error when exception occurs:

    try:
        transaction.commit()
    except Exception, e:
        session.rollback()
        print str(e)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can insert a array into my MySQL database? I have managed to insert
I am trying to insert into mysql database dynamically. But I always see only
I'm trying to insert into mysql but it giving me an error, here my
I'm trying to insert multiple rows into MySql with only one INSERT INTO statement
Here my code, I need to insert into mysql database I have mysql,php,android 1)
Based on this question How to insert array into mysql using PDO and bindParam?
The following query was successful when I used in mysql INSERT INTO user(`dev_id`,`email`) VALUES('123','456@gmail.com');
The only similar question I have found is: Insert php boolean into mysql bit
I am parsing a log and inserting it into either MySQL or SQLite using
When I insert 78.9 into Mysql (using JDBC) it gets rounded up to 79?

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.