Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNick Rowland
4,044 PointsKeyError: 'j'
when I run the entire program it gives me a KeyError: 'j' and points to line 4 where I have "import models"
Christian Basile
2,067 PointsI had a similar key error 'f' , would appreciate the help -Thanks
(base) Christians-MacBook-Pro:Sflask christianbasile$ python app.py
Traceback (most recent call last):
File "app.py", line 228, in <module>
models.initialize()
File "/Users/christianbasile/Desktop/Sflask/models.py", line 86, in initialize
DATABASE.create_table([User, Post, Relationship, Liketable], safe=True)
AttributeError: 'SqliteDatabase' object has no attribute 'create_table'
(base) Christians-MacBook-Pro:Sflask christianbasile$ python app.py
Traceback (most recent call last):
File "app.py", line 228, in <module>
models.initialize()
File "/Users/christianbasile/Desktop/Sflask/models.py", line 86, in initialize
DATABASE.create_tables([User, Post, Relationship, Liketable], safe=True)
File "/Users/christianbasile/opt/anaconda3/lib/python3.7/site-packages/peewee.py", line 3286, in create_tables
model.create_table(**options)
File "/Users/christianbasile/opt/anaconda3/lib/python3.7/site-packages/peewee.py", line 6595, in create_table
cls._schema.create_all(safe, **options)
File "/Users/christianbasile/opt/anaconda3/lib/python3.7/site-packages/peewee.py", line 5732, in create_all
self.create_indexes(safe=safe)
File "/Users/christianbasile/opt/anaconda3/lib/python3.7/site-packages/peewee.py", line 5645, in create_indexes
for query in self._create_indexes(safe=safe):
File "/Users/christianbasile/opt/anaconda3/lib/python3.7/site-packages/peewee.py", line 5634, in _create_indexes
for index in self.model._meta.fields_to_index()]
File "/Users/christianbasile/opt/anaconda3/lib/python3.7/site-packages/peewee.py", line 6011, in fields_to_index
fields.append(self.combined[part])
KeyError: 'f'
I fixed the error by adding a , next to true like this :
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 Liketable(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),) # <- , next to parenthesis in
1 Answer
KRIS NIKOLAISEN
54,971 PointsCan you post your code?
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 Points... and post the full error stack trace. Thx.