我用的是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")
也许这是一个错误?