Is there a way to set the id value of new Django objects to start at a certain value?

前端 未结 2 1122
北恋
北恋 2021-02-19 08:56

Is there a way to set the counter of id values for objects in Django?

For example I have an set of objects \'Video\' that are currently at id=100 the next time I create

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-19 09:54

    You can specify the ID when you create the object, as long as you do it before you save:

    new = Video()
    new.id = 2000
    new.save()
    

    You could just calculate the ID you wanted each time - though I'm not sure what's wrong with Django's auto ID fields ;)

提交回复
热议问题