Search code examples
postgresqlpeewee

How to custom the table name in peewee?


I want to define a table which the table name is gobang_server,i write code as follow:

class BaseModel(Model):
    class Meta:
        database = database

class GobangServer(BaseModel):
    time = DateField(default=datetime.datetime.now())
    name = CharField(max_length=64)
    host = CharField(max_length=30)
    port = IntegerField()
    pid = IntegerField()

but i look at PostgreSQL the table name is "gobangserver"?
How can i define with the table name is gobang_server and the class name is not be modified.


Solution

  • class GobangServer(BaseModel):
        ...
        class Meta:
            db_table = 'gobang_server'
    

    In peewee 3.0 it changes from "db_table" to "table_name".