In __your__ code, most certainly.  :-)

You didn't say what 'training', 'input_type' and 'gender' are. It is in one or 
more of those where the problem exists.

Do these referenced save module instances? If they are not yet saved then it 
will trigger this error for fields where



On 13 Oct 2020, at 08:49, Joakim Hove 
<joakim.h...@gmail.com<mailto:joakim.h...@gmail.com>> wrote:

Thank you for answering. Just to be sure: you agree that the behavior I 
describe looks like a bug somewhere?

man. 12. okt. 2020, 23:42 skrev Thomas Lockhart 
<tlockhart1...@gmail.com<mailto:tlockhart1...@gmail.com>>:
No one has answered yet, so here is some useless info…

I’ve been using various combinations of Postgres and Django (currently 12.4 and 
3.1.2, respectively) and would think I would have stumbled on this at some 
point when using postgresql-11. But I probably haven’t tried 11.x with 3.1.2 
specifically…

- Tom

On Oct 12, 2020, at 9:24 AM, Joakim Hove 
<joakim.h...@gmail.com<mailto:joakim.h...@gmail.com>> wrote:



[ This question is also posted to StackOverflow: 
https://stackoverflow.com/questions/64320386/django-postgresql-model-with-only-foreign-keys
 ]

I have a model which looks like this:

class InputTypeMap(models.Model):
    input_type = models.ForeignKey(InputType, on_delete=models.CASCADE)
    training = models.ForeignKey(Training, on_delete=models.CASCADE)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    gender = models.ForeignKey(Gender, on_delete=models.CASCADE)


When I try to create instances of this model with:

InputTypeMap.objects.create(input_type=input_type,
                            training=training,
                            gender=gender,
                            category=category)


I get an exception when using Postgres-11.9:

Traceback (most recent call last):
  File 
"/home/hove/sleipner/venv/lib/python3.7/site-packages/django/db/backends/utils.py",
 line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.NotNullViolation: null value in column "id" violates not-null 
constraint
DETAIL:  Failing row contains (null, Maintenance, Female, MareGielding, No).


>From the error message it seems to me that a ID key for the new entry is not 
>generated. This code has worked as I expected for quite some time, but has 
>"suddenly" started to fail locally - probably after a apt get upgrade. When I 
>run the same code with sqlite or Postgres-10.14 thing continue to work as 
>before. It is not clear to me whether this is a bug in my code (most probable 
>...), Django or Postgres. I am using Django version 3.1.2

Any hints appreciated.

Regards - Joakim Hove

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M-YbR80USkq%2BLLyWHR7iem66ALcc9bH6dYGOEP9ywWkfA%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CALKD1M-YbR80USkq%2BLLyWHR7iem66ALcc9bH6dYGOEP9ywWkfA%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1C816206-3EC7-4696-806E-FD810E76C251%40gmail.com<https://groups.google.com/d/msgid/django-users/1C816206-3EC7-4696-806E-FD810E76C251%40gmail.com?utm_medium=email&utm_source=footer>.

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M8O4%3DtQ%2BxuEE7%2BzC17%2BjnotzUzEDU3EkoqVTPDOTngQMg%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CALKD1M8O4%3DtQ%2BxuEE7%2BzC17%2BjnotzUzEDU3EkoqVTPDOTngQMg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/270DF6AB-0CF9-471B-AF95-B18959CFCF64%40uniquode.io.

Reply via email to