Hi all,

Problem: I want to use Transaction to save data to a postgresql-db.
Error: IntegrityError: doppelter Schlüsselwert (double keyvalue)
verletzt (harm) Unique-Constraint
»measurements_loggerdata_logger_id_key«

My Model looks like this:

class LoggerData(models.Model):
  logger = models.ForeignKey(Logger)
  datetime = models.DateTimeField(db_index=True)
  class Meta:
    unique_together = [('logger', 'datetime')]

Now i read from a file measurement-data. It should be possible to read
the same file as often as i want, but maybe, there is some new data
append to the file. So the problem is, that inside of the file, there
is some old and some new data. The old data should not be written to
the DB, the new Data should be writte to the DB.

My Method to write the data to DB looks like:

from django.db import transaction
obj = LoggerData(**params)
self.saveLoggerDataToDatabase(obj)

def saveLoggerDataToDatabase(self, obj):
        """ Save a LoggerData Object to the Database. Use a
Transaction for this."""
        transaction.enter_transaction_management()
        obj.save()
        try:
            transaction.commit()
        except(psycopg2.IntegrityError, psycopg2.InternalError), e:
            self.logger.error(str(e.message) + str(line[0]))
            transaction.rollback()#
        transaction.leave_transaction_management()

I also tried it without  transaction.enter_transaction_management()
and with a decorator (commit_manually() ). I tried with activated
Middleware and without. Nothing worked for me.

I also tried to coment out the commit() statement. The strange thing
was, that i got the same error. I thougt, without the commit()
statement, the DB would not get touched.

have you any suggestions?

Thanks,
Tom

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to