Peewee throws KeyError: 'f'
Peewee throws KeyError: 'f'
所以我无法弄清楚这里的错误是什么(我很确定我只是在做一些愚蠢的事情)。任何帮助,将不胜感激。
这里是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))
我没有将函数包含在 class 中,因为我认为不需要它。我不想让代码混乱。如果你们需要它,请告诉我。这是错误。 (我发现了类似错误的问题,但我仍然无法弄清楚我的问题是什么)
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 项元组中缺少逗号:
indexes = ((('from_user', 'to_user'), True),)
所以我无法弄清楚这里的错误是什么(我很确定我只是在做一些愚蠢的事情)。任何帮助,将不胜感激。 这里是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))
我没有将函数包含在 class 中,因为我认为不需要它。我不想让代码混乱。如果你们需要它,请告诉我。这是错误。 (我发现了类似错误的问题,但我仍然无法弄清楚我的问题是什么)
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 项元组中缺少逗号:
indexes = ((('from_user', 'to_user'), True),)