Auto_increment custom Primary Key in Peewee model

Viacheslav picture Viacheslav · Jun 27, 2014 · Viewed 7.5k times · Source

I want a primary key id field to be Bigint

class Tweets(Model):
    id = BigIntegerField(primary_key=True)
    ...

But it needs to be auto_incremented and I can't find a way in the Peewee docs. Please suggest if it's possible.

Update: I'm using MySql db.

Answer

Mathieu Rodic picture Mathieu Rodic · Jun 30, 2014

Peewee automatically generates an integer id column serving as primary key, having the auto_increment property. This is true for any table you create with Peewee.

It is very likely that IntegerField is enough for your needs; BigIntegerField is very rarely useful. Will you really need numbers bigger than 2147483647? Will you insert more than two billion rows?

See: http://dev.mysql.com/doc/refman/5.5/en/integer-types.html