Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto_increment custom Primary Key in Peewee model

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.

like image 446
Viacheslav Avatar asked Jun 27 '14 11:06

Viacheslav


2 Answers

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

like image 59
Mathieu Rodic Avatar answered Sep 19 '22 22:09

Mathieu Rodic


Peewee, as of 3.1, includes a BigAutoField which is an auto-incrementing integer field using 64-bit integer storage. Should do the trick:

http://docs.peewee-orm.com/en/latest/peewee/api.html#BigAutoField

like image 20
coleifer Avatar answered Sep 19 '22 22:09

coleifer