Create MySQL unique ID while inserting list eliments in a DB
Question: I'm actually downloading feeds from a homepage and try to write them into a
MySQL DB. The Feeds are published in RSS. Everything is working fine without
the creation of the unique ID. So the Insert command must be wrong!

Here is my Code:

    
    
    import feedparser
    import urllib2
    import cookielib
    import MySQLdb
    import time
    import datetime
    from cookielib import CookieJar
    from urllib2 import urlopen
    
    db = MySQLdb.connect(host="localhost", # your host, usually localhost
                     user="root", # your username - SELECT * FROM mysql.user
                     passwd="****", # your password
                     db="sentiment_analysis") # name of the data base
    
    cur = db.cursor()
    cur.execute("DROP TABLE IF EXISTS feeddata_lse")
    
    sql = """CREATE TABLE feeddata_lse (LSE_ID INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(LSE_ID),Unix_Timesstamp integer, III_Timestamp varchar(255), Source varchar(255), Title varchar(255), Text TEXT,  Link varchar(255), Epic varchar(255), CommentNr integer, Author varchar(255))"""
    cur.execute(sql)
    
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(CookieJar()))
    opener.addheaders = [{'User-agent','Mozilla/5.0'}]
    
    def feed_load(feed):
    return [(time.time(),
             entry.published,
             'lse',
             entry.title,
             entry.summary,
             entry.link,
             (entry.link.split('?ShareTicker=')[1]).split('&post=')[0],
             entry.link.split('&post=')[1],
             entry.author)
            for entry
            in feedparser.parse(feed).entries]
    
    def main():
    FEED_URL = "http://www.lse.co.uk/chat/recent/"
    feed = feed_load(FEED_URL)
    
    print feed[1][1]
    
    for item in feed:
        cur.execute("""INSERT INTO feeddata_lse VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)""",item)
    db.commit()
    

If I delete the `LSE_ID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(LSE_ID)` out
to the Insert statement everything works fine. My major problem with changing
the insert-part is that a RSS feed contains a list of feeds and every feed is
another list.

**Thank you for helping me.** Please explain you arguments with code examples
because I am very unexperienced. If you have any questions feel free to ask!

Here is the error report:

    
    
    Traceback (most recent call last):
    File "C:/Python27/MySQL_finalversion/rss_db_connection_mysql_v1.py", line 54, in <module>
    main()
    File "C:/Python27/MySQL_finalversion/rss_db_connection_mysql_v1.py", line 48, in main
    cur.execute("""INSERT INTO feeddata_lse VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)""",item)
    File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
    File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
    OperationalError: (1136, "Column count doesn't match value count at row 1")
    


Answer: The `LSE_ID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(LSE_ID)` line occurs in
the table creation statement, not the insert statement. If you remove a column
from the table creation statement, but leave your INSERT statement unchanged,
you will indeed get a "Column count doesn't match value" error because you're
attempting to insert one more column than is defined on your table.

I think you'll find you actually want to keep that primary key. Rather than
remove `LSE_ID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(LSE_ID)` from your
table creation statement, maybe try explicitly naming the columns in your
INSERT statement like so?

`INSERT INTO feeddata_lse(Unix_Timesstamp, III_Timestamp, Source, Title, Text,
Link, Epic, CommentNr, Author) VALUES (%s,%s,` ...

