I am confused as to how to drop entire columns on a Flask server using SQLAlchemy. I changed a variable name in one of my models, and after running $ flask db migrate
and $ flask db upgrade
the associated table now has two columns: one with the old name and one with the new name. My first part of the question is, how can I, at that point, change the column name when I have these two columns in the table? I have tried following the advice in this similar question's answer by modifying the script.py.mako file in my /migrations folder:
op.alter_column('table_name', 'old_col', nullable=False, new_column_name='new_col')
with no luck. I also tried using the batch_mode version of this code.
To make things worse, somewhere in the process I accidentally added data to this new column and now have two columns. So presently, I'd like to merge these two (over the NULL records), but haven't been able to find any relevant solutions to this.
I'd like to understand the answers to both situations should they arise again.