How do I make an auto increment integer field in Django?

后端 未结 8 1101
小鲜肉
小鲜肉 2020-12-02 19:37

I am making an Order model for a shopping cart and I need to make a field that auto increments when the order is made:

class Order(models.Model)         


        
8条回答
  •  悲哀的现实
    2020-12-02 20:37

    In django with every model you will get the by default id field that is auto increament. But still if you manually want to use auto increment. You just need to specify in your Model AutoField.

    class Author(models.Model):
        author_id = models.AutoField(primary_key=True)
    

    you can read more about the auto field in django in Django Documentation for AutoField

提交回复
热议问题