Peewee抛出KeyError:'f'

时间:2018-03-05 17:16:59

标签: python python-2.7 flask peewee flask-peewee

所以我无法弄清楚这里的错误是什么(我很确定我只是在做一些愚蠢的事情)。任何帮助,将不胜感激。 这是models.py

DATABASE = SqliteDatabase('social.db')

class User(UserMixin, Model):
    username = CharField(unique=True)
    email = CharField(unique=True)
    password = CharField(max_length=100)
    joined_at = DateTimeField(default=datetime.datetime.now)
    is_admin = BooleanField(default=False)

    class Meta:
        database = DATABASE
        order_by = ('-joined_at',)

class Post(Model):
    timestamp = DateTimeField(default=datetime.datetime.now)
    user = ForeignKeyField(User, related_name='posts')
    content = TextField()

    class Meta:
        database = DATABASE
        order_by = ('-timestamp',)

class Relationship(Model):
    from_user = ForeignKeyField(User, related_name = 'relationships')
    to_user = ForeignKeyField(User, related_name = 'related_to')

    class Meta:
        database = DATABASE
        indexes = ((('from_user', 'to_user'), True))

我没有在课程中包含这些功能,因为我觉得不需要它。我不想让代码混乱。请告诉我你是否需要它。这是错误。 (我发现有类似错误的问题,但我仍然无法弄清楚我的错误)

Traceback (most recent call last):
File "app.py", line 175, in <module>
  models.initialize()
File "/home/devang/Projects/Web-Apps/Flask/The Social Network/models.py", line 91, in initialize
  DATABASE.create_tables([User, Post, Relationship], safe=True)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2602, in create_tables
  model.create_table(**options)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 5317, in create_table
  cls._schema.create_all(safe, **options)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4593, in create_all
  self.create_indexes(safe=safe)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4522, in create_indexes
  for query in self._create_indexes(safe=safe):
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4511, in _create_indexes
  for index in self.model._meta.fields_to_index()]
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4842, in fields_to_index
  fields.append(self.combined[part])
KeyError: 'f'

谢谢!

1 个答案:

答案 0 :(得分:0)

单项元组中缺少逗号:

    indexes = ((('from_user', 'to_user'), True),)