Created
July 20, 2015 07:52
-
-
Save d30jeff/f1575a5d6b7133941b20 to your computer and use it in GitHub Desktop.
Alembic add non-null column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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