Unnecessary changes produced in migration file after running flask db migrate #1019
Replies: 2 comments 10 replies
-
hey there - so the Alembic autogenerate process performs the task of reading information about all the tables, columns, and constraints it can find on a target database, which it does with a live database connection, and compares what it sees to a declared model in Python code, which is delivered to Alembic in the form of a collection called With the fragments that are listed out here, I assume this is somewhat of a paraphrase, as typically we would see the things that are added/dropped inside the"upgrade()" method to have a corresponding drop/add inside the "downgrade". Like, the "upgrade" here tries to drop an index So without the fragments shown indicating any pattern, I can't give an exact reason for each entry. however, the fundamental reason for all of them can be broken down into:
op.alter_column('communication_items', 'name',
existing_type=sa.VARCHAR(),
type_=sa.Text(),
existing_nullable=False) that means the database had a column with the VARCHAR datatype and the model has it as Text(), which Alembic is not considering as the same (try using String() for the model datatype for that one in particular).
There's also some other suspicious things like the constraints with None for the name ( Overall it looks like you have an existing database with structures in it that were not created directly by the model you have (or have elements that were added to migrations manually that aren't in the model), so trying to reconcile these things for the first time can produce a lot of mismatches. There are solutions for all of them but they have to be taken on a case by case basis. |
Beta Was this translation helpful? Give feedback.
-
I am using SQL Alchemy version 1.3.19 and Flask version 1.1.1 and Alembic version 1.7.5 (not sure how to update it to 1.7.7)
Also the code above is also another snippet of the migration file. It's kind of weird how these changes were picked up because the existing data type for all the columns above in the model are all "Text" so I'm not sure what is being changed? Varchar to Text? |
Beta Was this translation helpful? Give feedback.
-
Hi all,
After running
flask db migrate
I am coming across an issue where the new migration file produced has changes that don't need to be there. Here is a snippet of the migration file's code:These changes don't appear to be here for any particular case, so not sure why they're occurring.
Beta Was this translation helpful? Give feedback.
All reactions