How to refresh model on db update

10 views
Skip to first unread message

Emanuele Gesuato

unread,
Feb 20, 2011, 10:28:48 AM2/20/11
to migrate-users
Hi there,
I'm using python 2.6 and sqlalchemy 0.6 with sqlalchemy-migrate 0.6
and i'm trying to build a simple migration script for my desktop
application.

The migration-script is available here
http://tinypaste.com/7faf74
and it works correctly: the two columns are correctly added to the
corresponding tables.

But the model data isn't updated with this new columns. If in
sqlalchemy i try to retrieve all the "articolo" objects using
session.query(Articolo).all()

the elements of the list doesn't have the attributes related to the
columns i added with the script. For instance in "articolo" there
isn't the attribute "qta_residua" associated with the corresponding
column in the table.

Why ?
Thanks for any help

Jan Dittberner

unread,
Feb 20, 2011, 10:39:31 AM2/20/11
to migrat...@googlegroups.com
I think you will have to reload your model if you want to use it with
the same connection (maybe a

meta = MetaData(bind=engine, reflect=True)

helps, depending on your application).

The "normal" use case is to perform migrations outside of the
application code (I usually do it in Pylons' websetup.py) and just
rely on a specific version of the schema in my model (checked at
application startup).


Regards
Jan

2011/2/20 Emanuele Gesuato <emanuele...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "migrate-users" group.
> To post to this group, send email to migrat...@googlegroups.com.
> To unsubscribe from this group, send email to migrate-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/migrate-users?hl=en.
>
>

--
Jan Dittberner
Software Architect - Debian Developer

Emanuele Gesuato

unread,
Feb 20, 2011, 12:10:22 PM2/20/11
to migrate-users
I have tried using reflect but it seems to work only if i have new
tables, not with new columns in existing tables.

Using

meta = MetaData(bind=engine, reflect=True)

or

meta.reflect(bind=engine)

after the migration doesn't work. The new attribute isn't present
inside the model, but the column is present in the table.

Thanks for any help



On 20 Feb, 16:39, Jan Dittberner <jan.dittber...@googlemail.com>
wrote:
> I think you will have to reload your model if you want to use it with
> the same connection (maybe a
>
>  meta = MetaData(bind=engine, reflect=True)
>
> helps, depending on your application).
>
> The "normal" use case is to perform migrations outside of the
> application code (I usually do it in Pylons' websetup.py) and just
> rely on a specific version of the schema in my model (checked at
> application startup).
>
> Regards
> Jan
>
> 2011/2/20 Emanuele Gesuato <emanuele.gesu...@gmail.com>:
>
>
>
>
>
> > Hi there,
> > I'm using python 2.6 and sqlalchemy 0.6 with sqlalchemy-migrate 0.6
> > and i'm trying to build a simple migration script for my desktop
> > application.
>
> > The migration-script is available here
> >http://tinypaste.com/7faf74
> > and it works correctly: the two columns are correctly added to the
> > corresponding tables.
>
> > But the model data isn't updated with this new columns. If in
> > sqlalchemy i try to retrieve all the "articolo" objects using
> > session.query(Articolo).all()
>
> > the elements of the list doesn't have the attributes related to the
> > columns i added with the script. For instance in "articolo" there
> > isn't the attribute "qta_residua" associated with the corresponding
> > column  in the table.
>
> > Why ?
> > Thanks for any help
>
> > --
> > You received this message because you are subscribed to the Google Groups "migrate-users" group.
> > To post to this group, send email to migrat...@googlegroups.com.
> > To unsubscribe from this group, send email to migrate-user...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/migrate-users?hl=en.
Reply all
Reply to author
Forward
0 new messages