【问题标题】:Peewee throws KeyError: 'f'Peewee 抛出 KeyError: 'f'
【发布时间】:2018-08-13 10:26:33
【问题描述】:

所以我无法弄清楚这里的错误是什么(我很确定我只是在做一些愚蠢的事情)。任何帮助,将不胜感激。 这是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'

谢谢!

【问题讨论】:

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


    【解决方案1】:

    1 项元组中缺少逗号:

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

    【讨论】:

      猜你喜欢
      • 2015-09-01
      • 2013-02-13
      • 2015-07-20
      • 2021-03-03
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2019-11-29
      • 2012-03-26
      相关资源
      最近更新 更多