In MySQL, we can use AUTO_INCREMENT = ? to automatically insert a primary key value. How do we do it in SQLAlchemy/Alembic? Thanks very much!
In MySQL, we can use AUTO_INCREMENT = ? to automatically insert a primary key
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
auto_increment is emitted within a CREATE TABLE if the type is “Integer, primary_key=True”. Within Alembic using alter_column, you need to specify it to alter_column.
See “autoincrement” and “existing_autoincrement” for alter_column() at:
https://alembic.readthedocs.org/en/latest/ops.html#alembic.operations.Operations.alter_column
See autoincrement for Column, note this defaults to True and you normally don’t need to change it, at:
http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#sqlalchemy.schema.Column.__init__