I want to use flask peewee as ORM for a relational db (MySQL) but my problem is changes in structure of models... like adding new attributes for a model (this means columns in db). I want to know if I can do this automatically without writing SQL manually?
3 Answers
It looks like the Peewee module does support migrations.
http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#schema-migrations

- 11,977
- 10
- 50
- 52
-
2Depends on what you want from a migration tool. Some migration tools handle data versioning for you and automatically applies the correct migrations to update the database to match the current schemas. The build-in peewee migration module does not do that. It just adds or removes columns, according to what your tell it to do. – Anders E. Andersen Jun 25 '16 at 08:51
I've wrote a simple migration engine for Peewee https://github.com/klen/peewee_migrate

- 1,595
- 12
- 11
-
Thanks, Kirill, it's really great! Hope you'll implement versioning feature anytime soon. – mangolier Mar 03 '15 at 13:47
We developed https://github.com/keredson/peewee-db-evolve for our company's use that sounds like it may be helpful for you.
Rather than manually writing migrations, db-evolve calculates the diff between the existing schema and your defined models. It then previews and applies the non-destructive SQL commands to bring your schema into line. We've found it to be a much more robust model for schema management. (For example, switching between arbitrary branches with different schema changes is trivial this way, vs. virtually impossible w/ manually authored migrations.)
Example:
Think of it as a non-destructive version of Peewee's create_tables()
. (In fact we use it for exactly that all the time, to build the schema from scratch in tests.)

- 3,019
- 1
- 17
- 20
-
2Amazing library! But I wish it worked with peewee 3.x too. Any chance you are working on an upgrade? – bman Jun 05 '18 at 04:01
-
1thanks! yes: https://github.com/keredson/peewee-db-evolve/tree/peewee3 pretty much complete - looking for testers if you want to give it a whirl. @bman – keredson Jun 05 '18 at 17:38
-
unfortunately, I can't even install it. I commented in this PR: https://github.com/keredson/peewee-db-evolve/pull/27 – bman Jun 06 '18 at 00:17
-