Index: django/db/backends/postgresql/operations.py
===================================================================
--- django/db/backends/postgresql/operations.py	(revision 1687)
+++ django/db/backends/postgresql/operations.py	(working copy)
@@ -55,7 +55,15 @@
         return '%s'
 
     def last_insert_id(self, cursor, table_name, pk_name):
-        cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
+        # This is tricky.  It's possible for len(seq_guts) to be exactly 59.  
+        # That's not too long, and Postgres doesn't clip it.  But, if the 
+        # tablename is 28, and the pk_name is 30, (plus the '_'), then 
+        # unconditionally clipping both parts to 29 removes an extra char, 
+        # and we get a wrong answer.
+        seq_guts = '%s_%s' % (table_name,pk_name)
+        if len(seq_guts) > 59:
+            seq_guts = "%s_%s" % (table_name[:29], pk_name[:29])
+        cursor.execute("SELECT CURRVAL('\"%s_seq\"')" % (seq_guts))
         return cursor.fetchone()[0]
 
     def no_limit_value(self):
