Recent migration generated by db migrate
wants to change all IDENTITY columns to INTEGER
#556
-
I have a pretty old app where I've used flask-migrate since the start. Love it. The app is pretty stable so I haven't had to touch my schema for a while. I'm guessing that something changed as I've updated sqlalchemy and other packages since the last time I needed I'm hoping for some advice / pointers on what's going on. Right now I'm commenting out all the wayward commands in the migration I need to apply this month. Since the app is so old maybe it was created with legacy DDL? Maybe there's a migration step I need to apply to my models? I haven't found any good search results in this repo or in Google. Thanks in advance for your time here. Relevant versions:
The database server is postgresql 14.15 (Ubuntu 14.15-1.pgdg24.04+1) Many of my models use a "standard" primary key column definition id = Column(Integer, primary_key=True) The output from
When generating my most recent migration for every one of those columns, the following command was generated. batch_op.alter_column(
"id",
existing_type=sa.INTEGER(),
server_default=None,
existing_nullable=False,
autoincrement=True,
) The matching downgrade command for each is batch_op.alter_column(
"id",
existing_type=sa.INTEGER(),
server_default=sa.Identity(
always=False,
start=1,
increment=1,
minvalue=1,
maxvalue=2147483647,
cycle=False,
cache=1,
),
existing_nullable=False,
autoincrement=True,
) If I try to execute the generated update commands (
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
What does the migration that defined this column originally say? |
Beta Was this translation helpful? Give feedback.
If I have to make a guess, I'd say that the database you are generating these migrations against does not match the definitions in your models and your previous migrations, and for that reason it is trying to make a correction to make everything match. I guess you can inspect the schema of the affected table(s) to see how the id is defined. The original migration that you copied above appears to agree with the definition that Flask-Migrate is trying to migrate to, so you either have some other migration that changed these ids to the other format, or else the database was changed outside of this application.
One thing you can try is to generate a new database by running all your migrations…