There's no magic bullet there, you'd need to write a query against your data and then run those rows into a print() statement that creates the Python code you want (if in a migration, these would be bulk_insert() statements).

Here's a really blunt example:

print("op.bulk_insert(")
for row in conn.execute(select([table])):
   print(repr(dict(row)) + ",")
print(")")

It's possibly more appropriate to use SQL dump files, depends on how many rows we are talking about.

On 06/01/2017 09:42 AM, Michael wrote:
Hi all, say I want to seed the db with initial data. I know can do this in a 
migration. But what if I want to take the data that is currently in the 
database and generate the Python code that will insert all of it? It would save 
me from entering all of this manually. Is there such a way to do that with 
sqlalchemy or alembic?

Regards,
Michael


--
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 sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to