small fixes for use with python 3.4, postgres, and many-to-many relations

replaced file->open (file is no longer a builtin in python3.4).  also postgres is very grumpy about integrity constraint violations (as it should be): it stopped complaining after these fixes.