0

I'm fairly new to Python and ORMs and I have a pretty specific question. To handle SQL, a Python ORM needs to have models defined, likely in a file called models.py, right?

Now, when I want to automatically create a new column when I add content to a table how do I avoid updating models.py manually every time?

To give you some context: I have a db with the tables Persons, Publications and Articles. I would like to create a table that takes an ID from Persons as a new column and then fills its rows with all the IDs of Publications that the Person is writing for (related via Articles).

In this question Damian Brecht points to sqlalchemy-migrate but I don't get how you keep the definition of the models updated, since every column is a line of code in models.py...

Community
  • 1
  • 1
ryneke
  • 11
  • 1
  • 2
  • The models drive the database, not the other way around. When you need a new row or table, you make the changes to the models and either run a migration or generate a new database from your defined models. – Celeo Sep 02 '16 at 23:39
  • "The models drive the databse, not the other way around." - Thanks, that did it for me. Guess I will have to look into migration then – ryneke Sep 03 '16 at 21:22

0 Answers0