Peewee模型是否有办法将名为“id”的默认主键更改为其他名称?
答案 0 :(得分:2)
有几种方式......
自动递增名为“pk”的整数字段:
class MyModel(Model):
pk = PrimaryKeyField()
other_field = TextField()
Varchar主键:
class MyModel(Model):
data = CharField(primary_key=True)
多列主键:
class MyModel(Model):
key = CharField()
value = CharField()
class Meta:
primary_key = CompositeKey('key', 'value')