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

Comments

Popular posts from this blog

Run tasks in background in Spring

Conditional field inclusion in Jackson and Spring Boot

How to configure Wildfly 10 to use MySQL