CoreyMSchafer/code_snippets

Facing issue - Python Flask framework -Part 4

sapnaneel opened this issue · 0 comments

Hello,
I am new to Python and Flask... I could follow the instructions on the Flask tutorial until I came across Sqlalchemy in Part 4 of the series.

I could import User and Post from flashblog in Python on command prompt. However when I try to create an instance of the user by setting the values for username, password and email I get an error. Can anyone please help me with this...When I execute the below...

user_1 = User(username='random', email='S@demo.com', password='password')

The error I get is:

File "C:\Users\S\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\orm\instrumentation.py", line 376, in _new_state_if_none state = self._state_constructor(instance, self)
File "C:\Users\S\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\util\langhelpers.py", line 883, in get obj.dict[self.name] = result = self.fget(obj)
File "C:\Users\S\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\orm\instrumentation.py", line 202, in state_constructor self.dispatch.first_init(self, self.class)
File "C:\Users\S\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\event\attr.py", line 322, in call fn(*args, **kw)
File "C:\Users\S\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\orm\mapper.py", line 3392, in _event_on_first_init configure_mappers()
File "C:\Users\S\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\orm\mapper.py", line 3276, in configure_mappers raise e
sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'mapped class User->user'. Original exception was: When initializing mapper mapped class User->user, expression 'Post' failed to locate a name ('Post'). If this is a class name, consider adding this relationship() to the <class 'flaskblog.User'> class after both dependent classes have been defined.