<p>"DataError: integer out of range" in psycopg may be caused when you have a table with an integer auto-incrementing id and you insert more than 2^31-1 records. Note that if you TRUNCATE the table, the id sequence DOES NOT reset. Use <code>ALTER SEQUENCE sequence-name RESTART WITH 1;</code> for that. Find out the sequence name with <code>\d+ table_name</code>.</p>