I use the following code to inserting data in DB:
db = dbConnection("localhost", "root", "")
class Products(peewee.Model):
article = peewee.TextField()
name = peewee.TextField()
price = peewee.TextField()
price_distributor = peewee.TextField()
price_discount = peewee.TextField()
class Meta:
database = db
Products.create_table()
book = Products(article="1", name="2", price="3", price_distributor="4", price_discount="5")
book.save()
And connection function:
def dbConnection(host, user, password):
return peewee.MySQLDatabase("test", host=host, port=3306, user=user, passwd=password)
How to set table name in which I insert data?
If you take a look at the docs on peewee model options
There is an option you can specify in class Meta
called db_table
which is the name of the table to store data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.