Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Thank you for your comment. I did specify Primary Key = personID. Did you miss it? Other than that, the error I got came from this line: to_db = [(i['personid'], i['age'], i['sex'], i['primary_voting_address_id'], i['state_code'], i['state_flips'], i['county_name'], i['county_fips'], i['city'], i['zipcode'], i['zip4']) for i in dr], so I am not sure if the line INSERT INTO.... is the reason. I still get the same error message when specifying ALL the column names, to be honest. Commented Sep 3, 2017 at 23:15
  • After I tried adding all the column names into INSERT INTO..., I got a new error message from the cursor.execute... statement: OperationalError: table person already exists. If I change the name of the table from person to person1, I ended up with the original error message at line 11: KeyError: 'personid'. Not sure why:( Commented Sep 3, 2017 at 23:20
  • @Marichyasana: personID is unique, isn't it? Did you take a look at the .csv files?? Commented Sep 3, 2017 at 23:27
  • @Marichyasana: could you try importing the two csv files by fixing my code above, and let me know what went wrong? I still could not see why I got that error:( Commented Sep 4, 2017 at 0:50
  • @ghjk I downloaded the two files using wget and checked the first one with csvlint and a little bit using R. Give me a little time and I'll see. Commented Sep 5, 2017 at 5:43