I just add django.middleware.transaction.TransactionMiddleware to
MIDDLEWARE_CLASSES, and get

OperationalError: ERROR:  insert or update on table
"transactions_meterreadings" violates foreign key constraint
"transactions_meterreadings_service_id_fkey"
DETAIL:  Key (service_id)=(43683) is not present in table
"organizations_organizationservice".

Now everything is clear for me :)

On 23 Січ, 17:29, sector119 <[EMAIL PROTECTED]> wrote:
> Hi All.
>
> Why I get this error?
> It's heppens in person_meter_readings view when request method is POST
> on MeterReadings.objects.create(**kw) line, I discovered this using
> print's with development server.
>
> def person_meter_readings(request, person_id):
> ...
>     if request.method == 'POST':
>         meter_readings = request.POST.getlist('readings')
>         person = get_object_or_404(Person, pk=person_id)
>
>         for i, readings in enumerate(meter_readings):
>             kw = {'person': person, 'service': services[i], 'meter':
> meters[i]['meter'], 'readings': readings}
>             MeterReadings.objects.create(**kw)
>         HttpResponseRedirect('/')
>
>     from django.shortcuts import render_to_response
>     return render_to_response('people/person_meter_readings.html',
> {'meters': meters})
>
> class MeterReadings(models.Model):
>     person = models.ForeignKey(Person, verbose_name=_('The related
> person.'))
>     service = models.ForeignKey(OrganizationService,
> verbose_name=_('The related organization service.'))
>     meter = models.PositiveIntegerField(_('Meter id'))
>     readings = models.PositiveIntegerField(_('Meter readings'))
>     datetime = models.DateTimeField(_('Commit date'),
> auto_now_add=True, db_index=True)
>
> Traceback (most recent call last):
>
>   File "/home/sector119/devel/django_src/django/core/servers/
> basehttp.py", line 277, in run
>     self.result = application(self.environ, self.start_response)
>
>   File "/home/sector119/devel/django_src/django/core/servers/
> basehttp.py", line 631, in __call__
>     return self.application(environ, start_response)
>
>   File "/home/sector119/devel/django_src/django/core/handlers/
> wsgi.py", line 212, in __call__
>     dispatcher.send(signal=signals.request_finished)
>
>   File "/home/sector119/devel/django_src/django/dispatch/
> dispatcher.py", line 360, in send
>     **named
>
>   File "/home/sector119/devel/django_src/django/dispatch/
> robustapply.py", line 47, in robustApply
>     return receiver(*arguments, **named)
>
>   File "/home/sector119/devel/django_src/django/db/backends/
> __init__.py", line 28, in close
>     self.connection.close()
>
> InterfaceError: connection already closed
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to