On Thu, Aug 29, 2013 at 3:54 PM, Aaron Krister Johnson
<[email protected]> wrote:
> Hi all,
>
> I have a script that bulk copies relevant data from one database server to
> another using the neat-o MetaData features in SQLAlchemy.
>
> My script is a custom variation of this script:
>
> http://www.tylerlesmann.com/2009/apr/27/copying-databases-across-platforms-sqlalchemy/
>
> My question is this: I want to have the import NOT over-write
> auto-incremented columns, i.e. I want it to respect when a column should be
> incremented on the destination table. So, is there a way to indicate that
> the copy process should copy everything *but* the auto-incremented columns?
>
> The documentation for SQLAlchemy is vast, butI haven't yet seen anything
> that clearly indicates this is possible.I feel certain it is there
> somewhere, but I'm surely missing it.
>

Columns have an "autoincrement" property, but from a quick look at the
source it probably doesn't quite do what you need. Tables have a
private _autoincrement_column property which returns the
autoincrementing column for that Table if one exists:

https://bitbucket.org/zzzeek/sqlalchemy/src/97168dbf69f8aa21de2e764a4a4993215cb9b726/lib/sqlalchemy/sql/schema.py?at=master#cl-503

As long as you are ok using a private property which may change or
disappear in future versions of SQLAlchemy, you could exclude this
column when copying the data.

However, if you've got any foreign keys pointing at those
auto-incrementing columns, this scheme will break, because the foreign
keys will be inserted with their old values rather than the new ones.
Fixing that would be much more complicated.

Hope that helps,

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to