How to get Django AutoFields to start at a higher number

前端 未结 7 708
挽巷
挽巷 2020-12-02 19:15

For our Django App, we\'d like to get an AutoField to start at a number other than 1. There doesn\'t seem to be an obvious way to do this. Any ideas?

7条回答
  •  再見小時候
    2020-12-02 20:06

    I needed to do something similar. I avoided the complex stuff and simply created two fields:

    id_no = models.AutoField(unique=True)
    my_highvalue_id = models.IntegerField(null=True)
    

    In views.py, I then simply added a fixed number to the id_no:

    my_highvalue_id = id_no + 1200

    I'm not sure if it helps resolve your issue, but I think you may find it an easy go-around.

提交回复
热议问题