Search code examples
djangopostgresqldjango-modelssequences

Django + Postgres: How to specify sequence for a field


I have this model in django:

class JournalsGeneral(models.Model):
    jid = models.AutoField(primary_key=True)
    code = models.CharField("Code", max_length=50)
    name = models.CharField("Name", max_length=2000)
    url = models.URLField("Journal Web Site", max_length=2000, blank=True)
    online = models.BooleanField("Online?")
    active = models.BooleanField("Active?")
    class Meta:
        db_table = u'journals_general'
        verbose_name = "Journal General"
        ordering = ['code']
    def __unicode__(self):
        return self.name

My problem is that in the DB (Postgres) the name of the sequence connected to jid is not journals_general_jid_seq as expected by Django but it has a different name.

Is there a way to specify which sequence Django has to use for an AutoField? In the documentation I read I was not able to find an answer.


Solution

  • I don't think so, but there is a ticket open for that (with a possibly useful patch?):

    http://code.djangoproject.com/ticket/1946

    Edit:

    Actually, that link above has a comment from HM on the thread with a better solution than the patch itself. The patch is old, I'm unsure if it will be applicable to the version of Django you are using.