1

I have a simple SQLAlchemy model, with a column for the ID:

    id = Column(Integer, primary_key=True)

This will start the id at 0, and autoincrement by 1. How do I make it start at 1000 instead of 0?

Newb
  • 2,810
  • 3
  • 21
  • 35
  • 1
    Possible duplicate of [Setting SQLAlchemy autoincrement start value](https://stackoverflow.com/questions/10494033/setting-sqlalchemy-autoincrement-start-value) – shmee Oct 18 '19 at 05:42
  • @shmee no, that's for setting the *autoincrement* value, not the start value. – Newb Oct 18 '19 at 05:43
  • The solution you just accepted, using SQLA's [Sequence](https://docs.sqlalchemy.org/en/13/core/defaults.html#sqlalchemy.schema.Sequence) object is exactly what is outlined in Edwardr's [answer](https://stackoverflow.com/a/10495449/4134674) in the linked Q&A. – shmee Oct 18 '19 at 05:55

1 Answers1

2

Maybe this will work for you:

from sqlalchemy.schema import Sequence

id = Column(Integer, Sequence('id_sequence', start=1000, increment=1), primary_key=True)
Kostas Charitidis
  • 2,991
  • 1
  • 12
  • 23