title: Adding data to a MySQL database using Python
body: <p>I'm looking for some general advice as to how to go about adding data to a MySQL database using python, and the MySQLdb package.
  I have a database created through java.
  I now want to parse a text file using python to populate this database. I am having problems with non-nullable columns, which means that I have to be strict about the order by which I add to the database, which doesn't seem very flexible. What I imagine would be best is be some kind of while statement that loops through the tables of the database, checking for non-nullable columns (which aren't auto-incremented), and comparing this to perhaps a list of sql commit statements. If non-nullable columns are found in the table, and a value for this is not found in the sql statement, the sql statement could be saved for later. Otherwise the statement could be committed to the database, and any auto-incremented values collected at that time. Then by looping back through the list of sql statements, attempt to fill in non-nullable values based on the auto-incremented values from the previous sql commits. I'm guessing this would be the best way to do it, but I'm not sure if I'm reinventing the wheel- surely this is quite a common problem? Just wondered if anyone knew of a better way to get around the problem of non-nullable columns, or if the above sounds reasonable, what would the python code look like to get a list of the non-nullable columns from a MySQL table, minus the auto-incremented columns?</p>