'How do you connect to an existing database table in peewee?
Much of the tutorials I've read show how to connect to the database and create a new table. Maybe I am wrong or misunderstanding , Ive reading the documents here: peewee offical
It shows how to connect to a db like so:
mysql_db = MySQLDatabase('my_app', user='app', password='db_password',
host='10.1.0.8', port=3306)
and it shows how to create a new table like so:
class User(Model):
username = CharField()
join_date = DateTimeField()
about_me = TextField()
But I want to know if I already have a database table with data in it how do I connect to it so I can add new records to it?
Thanks
Solution 1:[1]
Peewee does include a utility to look at an existing database and create model code to interact with that database. Here's a link describing it in the documentation: https://peewee.readthedocs.io/en/latest/peewee/playhouse.html#pwiz-a-model-generator . I haven't used this so can't vouch for how well it works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | manganmus |
