#25343: pk attribute not set when having own primary key
-------------------------------------+-------------------------------------
Reporter: IlianIliev | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by carljm):
Is this really your exact code? Unless you have `null=True` on the
`language` field, that code should raise a database error like "null value
not allowed in column 'language'".
But it looks like your database is automatically setting a value for that
field instead of raising an error. So maybe your database schema doesn't
match your model definition? What database are you using, and what is the
actual schema for that table? Did Django create it, or did you create it
manually?
If you set a value for the `language` field, that will be the value of the
`pk` attribute.
If you don't want to have to explicitly set a value for the primary key,
you should be using `AutoField`, not `IntegerField` (or just let Django
automatically add an `AutoField` named `id`, as it does if you don't set
`primary_key=True` on any of your fields).
--
Ticket URL: <https://code.djangoproject.com/ticket/25343#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.31300b1858beb66f5338e8415ddfcd5a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.