Opened 7 years ago

Closed 7 years ago

#10350 closed (worksforme)

Model with one field and field is unique -> field data become pk

Reported by: laundro@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords: unique pk
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


class Subscriber(models.Model):
    email = models.EmailField(unique = True)

>>> s = Subscriber(email = "")
ValueError: invalid literal for int() with base 10: ''

It appears the email field is automatically being used as the pk field, where the Django docs specifically state that:
By default, Django gives each model the following field:
id = models.AutoField(primary_key=True)


Change History (2)

comment:1 Changed 7 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I'm not seeing this at all (eventual exception is because I didn't create the table, you got an error before that point). Please try to provide some additional details as to what's going on otherwise I'm going to wontfix.

comment:2 Changed 7 years ago by Alex

  • Resolution set to worksforme
  • Status changed from new to closed

No new news on this front, marking as worksforme.

Note: See TracTickets for help on using tickets.
Back to Top