在Django模型中设置主键起始值 [英] Setting primary key start value in Django model
问题描述
我正在准备一个模型如下:
I am preparing a model as follows:
class SomeModel(models.Model):
id = models.BigIntegerField(primary_key=True, null=False, unique=True)
但是我的主键必须一个有效的9位数字的整数值。如果我将起始索引设置为 100000000
。那么以 id
生成的任何值将是9位数或更大的长度。
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.
但是django不支持这个。如何使用最小直接干扰来实现这个目标到django?
But django do not support this. How can I implement this with minimum direct interference to django?
我正在使用 Django 1.3
和 Postgresql 9.1
推荐答案
我不是一个django用户但我认为您要查找的postgresql命令是:
I'm not a django user but I think the postgresql command you are looking for is:
ALTER SEQUENCE big_integer_seq RESTART 100000000;
最好阅读django / postgresql的文档。
Best to read the documentation for django/postgresql.
这篇关于在Django模型中设置主键起始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!