I'm trying to delete but it's happening a strange error.

models:
class Account(models.Model):
    pass


class Action(models.Model):
    account = models.ForeignKey('Account', on_delete=models.CASCADE)


class Log(models.Model):
    account = models.ForeignKey('Account', on_delete=models.CASCADE)


class ActionLog(Log):
    action = models.ForeignKey('Action', on_delete=models.SET_NULL)


shell:

account = Account.objects.create()
action = Action.objects.create(account=account)
ActionLog.objects.create(account=account, action=action)
account.delete()


error:

insert or update on table "myapp_log" violates foreign key constraint 
"myapp_log_account_id_6ea8d7a6_fk_myapp_account_id"
DETAIL:  Key (account_id)=(11) is not present in table "myapp_account".

But:
>>> Account.objects.last().id
11


Why it happen? How solve it? Is a bug?
I am using PostgreSQL 9.3 and Django 1.9.5

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cc86e56d-d4c7-4230-9b51-51ae19de3a01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to