Hi,
I've been using alembic successfully for a couple of (simpler) database
migrations within my project. Now I want to delete a class from my model
and provide the appropriate alembic upgrade() and downgrade() scripts.
While the upgrade() methods work perfectly:
def upgrade():
# drop foreign keys and so forth
...
# this drops some data that can be reconstructed using other table data
op.drop_table('dog')
I really have problems with the downgrade() part:
def downgrade():
### commands auto generated by Alembic - please adjust! ###
dog_table = op.create_table('dog',
sa.Column('id', sa.INTEGER(), primary_key=True,
autoincrement=True),
sa.Column('mammal_id', sa.INTEGER()),
sa.ForeignKeyConstraint(['mammal_id'], [u'mammal.id'],
name=u'dog_mammal_id_fkey'),
sa.PrimaryKeyConstraint('id', name=u'dog_pkey'))
# if dog_table is None:
# raise Exception('Where is dog_table?')
# reconstruct data previously dropped
new_dogs = reconstruct_dogs()
print new_dogs
# this prints out: [{'mammal_id': 5, 'id': 0}, {'mammal_id': 2, 'id':
1}]
try:
op.bulk_insert(dog_table, new_dogs)
except:
op.bulk_insert('dog', new_dogs)
which fails with
line 180, in bulk_insert
table._autoincrement_column = None
AttributeError: 'str' object has no attribute '_autoincrement_column'
And this is because dog_table is None. At this time my model does not
contain a Dog class. If I don't do the bulk_insert(), the dog table is
created within the database.
How do I get the reconstructed dogs in the database again, so that my
downgrade() works as expected?
Any help would be greatly appreciated,
Tom
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.