Setting primary key start value in Django model

China☆狼群 提交于 2019-12-19 21:54:49

问题


I am preparing a model as follows:

class SomeModel(models.Model):
    id = models.BigIntegerField(primary_key=True, null=False, unique=True)

But my primary key must be a valid 9+ digit integer value. If I set the start index as 100000000. then any value generated as id will be 9 digit or greater in length.

But django do not support this. How can I implement this with minimum direct interference to django?

I am using Django 1.3 and Postgresql 9.1


回答1:


I'm not a django user but I think the postgresql command you are looking for is:

ALTER SEQUENCE big_integer_seq RESTART 100000000;

Best to read the documentation for django/postgresql.



来源:https://stackoverflow.com/questions/21095825/setting-primary-key-start-value-in-django-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!