编程语言
首页 > 编程语言> > python – Peewee没有设置最后一个插入ID

python – Peewee没有设置最后一个插入ID

作者:互联网

我用的是mysql数据库.保存后,Peewee没有设置id字段

Peewee型号:

class OAuthAccount(BaseModel):
    id = BigIntegerField(primary_key=True,index=True,unique=True , db_column="id")
    oauth_provider_id = IntegerField(null=False)
    oauth_uid = CharField()
    oauth_token = CharField()
    oauth_token_secret = CharField()
    username = CharField()
    inserter = BigIntegerField(null=True,db_column="inserter_id")
    insert_date = DateTimeField(null=True,default=fn.NOW())
    updater = BigIntegerField(null=True,db_column="updater_id")
    update_date = DateTimeField(null=True)
    extra_data = CharField()

保存代码:

oauthUser = OAuthAccount(
                    oauth_provider_id= formData.get("oauth_provider_id"),
                    oauth_uid = formData.get("oauth_uid"),
                    oauth_token = formData.get("oauth_token"),
                    oauth_token_secret=formData.get("oauth_token_secret"),
                    username = formData.get("username"),
                    inserter_id = g.auth.userId(),
                    extra_data = formData.get("extra_data")
                )
oauthUser.save()
print "id => " + str(oauthUser.id)

输出为:id =>没有

该行已成功插入数据库.但是id仍然是None

解决方法:

我不明白但是当我做这个改变时它起作用了:

id = BigIntegerField(primary_key=True,index=True,unique=True , db_column="id")        
->
id = BigIntegerField( db_column="id")

它也适用于这种变化:

id = BigIntegerField(primary_key=True,index=True,unique=True , db_column="id")
->
id = PrimaryKeyField( db_column="id")

当我把primary_key = True时它不起作用.

id = BigIntegerField(primary_key=True , db_column="id")

也许这是一个错误?

标签:python,mysql,peewee
来源: https://codeday.me/bug/20190628/1315513.html