两台服务器,不同的结果。相同版本的peewee,相同版本的mysql,相同的python(2.7.10)
代码:
from peewee import *
import pprint
mysql_db = MySQLDatabase('my_database', user="root", password="")
class ItemType(Model):
id = IntegerField()
name = CharField()
sort_order = IntegerField()
class Meta:
database = mysql_db
db_table = 'item_type'
class SubType(Model):
id = IntegerField()
name = CharField()
item_type_id = IntegerField()
item_type = ForeignKeyField(ItemType)
class Meta:
database = mysql_db
db_table = 'sub_type'
class Item(Model):
id = IntegerField()
name = CharField()
hash_id = CharField()
last_update = DateField()
basic = BooleanField()
sub_type_id = IntegerField()
item_type = ForeignKeyField(ItemType)
sub_type = ForeignKeyField(SubType)
user_id = IntegerField()
item_type_id = IntegerField()
class Meta:
database = mysql_db
db_table = 'item'
class Attribute(Model):
id = IntegerField()
name = CharField()
sort_order = IntegerField()
basic = BooleanField()
item_type_id = IntegerField()
item_type = ForeignKeyField(ItemType)
user_id = IntegerField()
class Meta:
database = mysql_db
db_table = 'attribute'
class ItemAttribute(Model):
id = IntegerField()
value = IntegerField()
item_id = IntegerField()
attribute_id = IntegerField()
item = ForeignKeyField(Item)
attribute = ForeignKeyField(Attribute)
class Meta:
database = mysql_db
db_table = 'item_attribute'
class ItemDetail(Model):
id = IntegerField()
small_image = CharField()
large_image = CharField()
description = TextField()
item_specific_json = TextField()
item = ForeignKeyField(Item)
class Meta:
database = mysql_db
db_table = 'item_detail'
class User(Model):
name = CharField()
last_login = DateField()
device_id = CharField()
hash = CharField()
id = IntegerField()
class Meta:
database = mysql_db
class UserAttribute(Model):
id = IntegerField()
sort_order = IntegerField()
attribute = ForeignKeyField(Attribute)
user = ForeignKeyField(User)
class Meta:
database = mysql_db
db_table = 'user_attribute'
class UserBlockedItem(Model):
id = IntegerField()
item_id = IntegerField()
user_item_id = IntegerField()
user = ForeignKeyField(User)
class Meta:
database = mysql_db
db_table = 'user_blocked_item'
class UserItem(Model):
id = IntegerField()
default_attributes = BooleanField()
user = ForeignKeyField(User)
item = ForeignKeyField(Item)
class Meta:
database = mysql_db
db_table = 'user_item'
class UserItemAttribute(Model):
id = IntegerField()
value = IntegerField()
item = ForeignKeyField(Item)
attribute = ForeignKeyField(Attribute)
user = ForeignKeyField(User)
class Meta:
database = mysql_db
db_table = 'user_item_attribute'
if __name__ == "__main__":
mysql_db.connect()
pprint.pprint(ItemAttribute.item_id)
pprint.pprint(ItemAttribute.attribute_id)
我的mac上的输出:
<peewee.IntegerField 对象在 0x10b243250>
<peewee.IntegerField 对象在 0x10b243290>
在我的服务器上输出
<peewee.IntegerField 对象在 0x1779810>
没有任何
怎么回事?
另一个线索。如果我将其更改为:
class ItemAttribute(Model):
id = IntegerField()
value = IntegerField()
item_id = IntegerField()
attribute_idx = IntegerField()
attribute_id = IntegerField()
item = ForeignKeyField(Item)
attribute = ForeignKeyField(Attribute)
class Meta:
database = mysql_db
db_table = 'item_attribute'
和这个:
pprint.pprint(ItemAttribute.item_id)
pprint.pprint(ItemAttribute.attribute_idx)
pprint.pprint(ItemAttribute.attribute_id)
它打印出这个:
<peewee.IntegerField 对象在 0x19d1890>
<peewee.IntegerField 对象在 0x19d18d0>
<peewee.IntegerField 对象在 0x19d1910>