我正在使用Peewee for Python并尝试更新实例的名称,但不是更新实例,而是将其添加为新实例。有什么问题?
from peewee import *
from datetime import date
db=SqliteDatabase('people.db')
class Person(Model):
name=CharField()
birthday=DateField()
is_relative=BooleanField()
class Meta:
database=db
class Pet(Model):
owner=ForeignKeyField(Person,related_name='pets')
name=CharField()
animal_type=CharField()
class Meta:
database=db
db.connect()
db.create_tables([Person,Pet],safe=True)
uncle_bob=Person(name='Bob',birthday=date(1960,1,15),is_relative=True)
uncle_bob.save()
grandma = Person.create(name='Grandma', birthday=date(1935, 3, 1), is_relative=True)
herb = Person.create(name='Herb', birthday=date(1950, 5, 5), is_relative=False)
grandma.name='Grand Dadi'
grandma.save()
我得到下表:
1|Bob|1960-01-15|1
2|Grandma|1935-03-01|1
3|Herb|1950-05-05|0
4|Bob|1960-01-15|1
5|Grand Dadi|1935-03-01|1
6|Herb|1950-05-05|0