Opened 5 years ago

Closed 5 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)


Attachments (0)

Change History (2)

comment:1 Changed 5 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 5 years ago by Alex

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

No new news on this front, marking as worksforme.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.