Search code examples
pythonpython-2.7flaskpeeweeflask-peewee

Peewee throws KeyError: 'f'


So I can't figure out what the error here is (I'm pretty sure I'm just doing something stupid). Any help would be appreciated. Here's 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))

I haven't included the functions inside the class as I don't think it's needed. I don't want to clutter with code. Please tell me if you guys need it. Here's the error. (I found questions with similar errors but I still coulnd't figure out what's wrong in mine)

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'

Thank you!


Solution

  • Missing comma in 1-item tuple:

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