On Mar 25, 2012, at 7:21 PM, John Anderson wrote:
> I have an existing app that I want to add some features to, so I created the
> new models and then ran --autogenerate and it created me a revision file
> where in downgrade it was creating all my files and in upgrade it was
> dropping the tables. That was backwards from what I expected, since my
> database didn't have the tables but the model did.
>
> Am I thinking about this in the wrong way?
>
> def upgrade():
> ### commands auto generated by Alembic - please adjust! ###
> op.drop_table(u'presentation')
> op.drop_table(u'file')
> ### end Alembic commands ###
>
> def downgrade():
> ### commands auto generated by Alembic - please adjust! ###
> op.create_table(u'presentation',
> sa.Column(u'pk', sa.INTEGER(),
> server_default='nextval('presentation_pk_seq'::regclass)', nullable=False),
> sa.Column(u'name', sa.TEXT(), nullable=True),
> sa.Column(u'description', sa.TEXT(), nullable=True),
> sa.Column(u'presenter', sa.TEXT(), nullable=True),
> sa.Column(u'date', postgresql.TIMESTAMP(), nullable=True),
> sa.PrimaryKeyConstraint(u'pk', name=u'presentation_pkey')
> )
> op.create_table(u'file',
> sa.Column(u'pk', sa.INTEGER(),
> server_default='nextval('file_pk_seq'::regclass)', nullable=False),
> sa.Column(u'user_pk', sa.INTEGER(), nullable=False),
> sa.Column(u'mimetype', sa.TEXT(), nullable=False),
> sa.Column(u'uid', sa.TEXT(), nullable=False),
> sa.Column(u'filename', sa.TEXT(), nullable=False),
> sa.Column(u'size', sa.INTEGER(), nullable=False),
> sa.ForeignKeyConstraint(['user_pk'], [u'user.pk'],
> name=u'file_user_pk_fkey'),
> sa.PrimaryKeyConstraint(u'pk', name=u'file_pkey')
> )
> ### end Alembic commands ###
the autogen you're illustrating here indicates that when you ran
--autogenerate, the database had two tables already present - "presentation"
and "file", and the MetaData object you passed to EnvironmentContext.configure
contained no tables. Autogen then tries to generate the changes that would
relate to making the database look just like the model you gave it - in this
case removing those tables in the database which aren't in the model.
Not sure how you're describing the opposite setup producing this, that's not
how autogenerate works.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.