0

I can successfully generate a database model, however I can't seem to figure out how to populate the database with data.

I believe the error lies in the command I used to autogenerate

alembic -x data=true upgrade head

does not produce any data, though after looking at my generated file, there is nothing in data_upgrade() or data_downgrade().

The command I am using to generate an auto migration is

alembic revision --autogenerate -m "migration_objective"

This then upgrades head to what is expected, but with no data in any of the tables.

Am I missing an option flag? I can't seem to find documentation on additional flags to use at this stage.

Lukabratzee
  • 137
  • 1
  • 10

1 Answers1

1

Alembic AutoGenerate will not detect data changes.

You'll need to pull the data out of the database to something like a CSV file which you can then parse and insert to the database during your upgrade

badger0053
  • 1,179
  • 1
  • 13
  • 19
  • Not changes per se, initialization is what I'm looking for. The only method I have of creating multiple test db's on the fly is using Alembic to create the structure then using sqldump to restore as a backup copy. This isn't bad, but it'd be nice to roll into one migration script without manually inputting data under data_upgrade(). I didn't see mention of Alembic being able to parse .csv data, is this a feature? – Lukabratzee Nov 15 '19 at 10:01
  • 1
    @Lukabratzee Unfortunately, no, nothing like that is built into alembic. If you're looking for something more dynamic than a csv file or sqldump you could leverage sqlalchemy. [inspector](https://docs.sqlalchemy.org/en/13/core/reflection.html#fine-grained-reflection-with-inspector) can help dynamically create the ddl and you could also create functions to query the data from the original tables and insert into the new tables – badger0053 Nov 15 '19 at 17:35