Posts

Showing posts from May, 2017

Generate model class in peewee

peewee is a very lighweight but rich orm for python. Often we need to generate model classes from an existing database table. It's possible to do this in peewee using an addon pwiz model generator . After installing pwiz, use the following command to generate model classes from an existing database. python -m pwiz -e mysql -u root -H localhost -P pesp_db > models.py Here is a brief description of the options: -e : name of the database engine e.g. mysql, postgresql -u : name of db user -H: name of db host The last parameter pesp_db in this case is the name of the database schema. If you run this command, you'll be prompted to provide your password. After providing the password, the model classes will be generated and written in the models.py