Skip to content

Instantly share code, notes, and snippets.

@d30jeff
Created July 20, 2015 07:52
Show Gist options
  • Select an option

  • Save d30jeff/f1575a5d6b7133941b20 to your computer and use it in GitHub Desktop.

Select an option

Save d30jeff/f1575a5d6b7133941b20 to your computer and use it in GitHub Desktop.
Alembic add non-null column
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('location', sa.Column('key', sa.String(length=36)))
op.execute("UPDATE location SET key='NA'")
op.execute("ALTER TABLE location ALTER COLUMN key SET NOT NULL")
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('location', 'key')
### end Alembic commands ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment