簡體   English   中英

如何指定表以使用peewee插入數據?

[英]How to specify table for inserting data using peewee?

我使用以下代碼在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()

並連接功能:

def dbConnection(host, user, password):
    return peewee.MySQLDatabase("test", host=host, port=3306, user=user, passwd=password)

如何設置要在其中插入數據的表名?

如果您查看有關peewee模型選項的文檔

您可以在class Meta指定一個選項,稱為db_table ,這是用於存儲數據的表的名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM