Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add a new column after another existing column in flask-migrate?

flask-migrate detected my column changes and was able to successfully create and execute the migration.

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('vtuber_info', schema=None) as batch_op:
        batch_op.add_column(sa.Column('model', sa.VARCHAR(length=128), server_default='', nullable=False, comment='model info'))

However, I found that the new column was placed at the end of the table column, which is not good enough for viewing the data because I often use visual database management tools to view my data, such as Sequel Pro, and I have many data fields in a row, so I often need to scroll to the right to see the end of the table column data.

so do you have any suggestions?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

BTW: My flask-migrate version is 4.0.4

>Solution :

This has little to do with flask or flask-migrate. Most database engines will add a column to the end of the table. One option is to rename the table, create a new table with columns in the order you want, and then copy data from the old table to the new table. As you can imagine this will take more time than just adding a single column.

Another option is to see if your visual database tool allows you to reorder the columns in the UI.

If neither of these work, then maybe you can create a view in the database with columns in the order you want.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading