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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:45:26+00:00 2026-06-13T22:45:26+00:00

I tried to fill a table in a database using MySQLdb. It did not

  • 0

I tried to fill a table in a database using MySQLdb. It did not give any errors, and once gave the warning

main.py:23: Warning: Data truncated for column 'other_id' at row 1
  cur.execute("INSERT INTO map VALUES(%s,%s)",(str(info[0]).replace('\n',''), str(info[2].replace('\n','').replace("'",""))))

so I thought it was working fine. However, when it was finished and I did a row count it turned out that nothing was added. Why was the data not added to the database? The code is below

def fillDatabase():
    db = MySQLdb.connect(host="127.0.0.1", 
                         user="root", 
                         passwd="", 
                         db="uniprot_map") 

    cur = db.cursor() 
    conversion_file = open('idmapping.dat')
    for line in conversion_file:
        info = line.split('\t')
        cur.execute("INSERT INTO map VALUES(%s,%s)",(str(info[0]).replace('\n',''), str(info[2].replace('\n','').replace("'",""))))

def test():
    db = MySQLdb.connect(host="127.0.0.1", 
                         user="root", 
                         passwd="", 
                         db="uniprot_map") 

    cur = db.cursor() 
    cur.execute("SELECT COUNT(*) FROM map")
    rows = cur.fetchall()

    for row in rows:
        print row

def main():
    fillDatabase()
    test()
  • 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-13T22:45:26+00:00Added an answer on June 13, 2026 at 10:45 pm

    You need to do a db.commit() after adding all of the entries. Even if the update is not transactional, the DBAPI imposes an implicit transaction on every change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML table with dynamically generated rows (using MVC3's EditorFor). Users fill
I tries to fill webgrid using one answered question and an article , But
Tried to create a mobile navigation using dataview or outline and the view renders
I have created a database and a table. I have also created all the
I am using SqlBulkCopy object to write a datatable into an sql server table.
I'm now using this code to import csv data into my database.(Thanks to Francis
I have a main page where you fill in some data. After you click
Scenario : i have a database table that is being updated frequently by some
I was wondering how I can pull down a portion of a table using
What I tried to do is generating a text file on ASP.Net using C#.

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.