2

Is there a way to add columns to an existing table using sqlalchemy? Looking at options, it seems like sqlalchemy-migrate is the popular option, but it seems to be designed around static changes. It also requires setting up the DB to support migration and running scripts outside of my main application to update. I want to be able to simply add new columns, not remove old ones to maintain data if a specifc xml is edited.

I'm not interested in defending this design, I just want to know if there is a way.

Logick
  • 301
  • 1
  • 6
  • 14

1 Answers1

0

According to SQLAlchemy Migrate's documentation, you can use the changeset module independently of SQLAlchmey Migrate's versioning. Thus you could do something like:

from migrate.changeset import *

table = Table('mytable', meta,
              Column('id', Integer, primary_key=True)
        )
table.create()

col = Column('col1', String, default='foobar')
col.create(table, populate_default=True)
mattjbray
  • 565
  • 3
  • 8