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 trial

Python Build a Social Network with Flask How to Win Friends Follow and Unfollow Buttons

Christian Basile
Christian Basile
2,067 Points

typeError missing 1 required positional argument:'model'

(base) Christians-MacBook-Pro:Sflask christianbasile$ python app.py Traceback (most recent call last): File "app.py", line 9, in <module> import forms File "/Users/christianbasile/Desktop/Sflask/forms.py", line 2, in <module> from models import User File "/Users/christianbasile/Desktop/Sflask/models.py", line 65, in <module> class Post(Model): File "/Users/christianbasile/Desktop/Sflask/models.py", line 67, in Post user=ForeignKeyField(rel_model=User, related_name='posts') TypeError: init() missing 1 required positional argument: 'model'

I would appreciate the help. Thanks

1 Answer

Steven Parker
Steven Parker
231,271 Points

The error message indicates that "models.py", line 67, has this line (indentation uncertain):

user=ForeignKeyField(rel_model=User, related_name='posts')

This line is clearly passing arguments for "rel_model" and "related_name", but the error says that the definition requires an argument named 'model' which is missing.

You may need to review the definition for "ForeignKeyField" to determine if this argument should be supplied, or eliminated or made optional in the definition.

Christian Basile
Christian Basile
2,067 Points

Thank you , I am new to flask , it seems the libraries changed, I changed : This ...... class Post(Model): timestamp = DateTimeField(default=datetime.datetime.now) user=ForeignKeyField(rel_model=User, related_name='posts') content= TextField('-timestamp',)

to This: and it solved the problem! Thanks , now I am trying to see what changed in wtforms.validators , -Thanks for the help.

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

Christian Basile
Christian Basile
2,067 Points

This fixed the problem, thank you Steven. class Post(Model): timestamp = DateTimeField(default=datetime.datetime.now) user=ForeignKeyField(model=User, backref='posts') content= TextField('-timestamp',) class Meta: database=DATABASE