如何在 PeeWee 中更新表格的列和列数据类型?
我已经从我的模型创建了数据库中的表格
以下内容不会更新表格结构:
我已经从我的模型创建了数据库中的表格
Person
。但是,我现在向模型添加了一些新字段并更改了某些现有字段/列的类型。以下内容不会更新表格结构:
psql_db = PostgresqlExtDatabase(
'MyDB',
user='foo',
password='bar',
host='',
port='5432',
register_hstore=False
)
class PsqlModel(Model):
"""A base model that will use our Postgresql database"""
class Meta:
database = psql_db
class Person(PsqlModel):
name = CharField()
birthday = DateField() # New field
is_relative = BooleanField() # Field type changed from varchar to bool
def __str__(self):
return '%s, %s, %s' % (self.name, self.birthday, self.is_relative)
psql_db.connect()
# is there a function to update/change the models table columns??
psql_db.create_tables([Person], True) # Hoping an update of the table columns occurs
# Error because no column birthday and incorrect type for is_relative
grandma_glen = Person.create(name='Glen', birthday=date(1966,1,12), is_relative=True)