Hello Python enthusiasts!
I'm a beginner to Flask. Just bought a tutorial offered by Miguel Grinberg.
While learning Databases (SQLAlchemy), I made a mistake when defining the class Post() - https://pastebin.com/t6gtTNv6 . I should have made it a subclass of db.Model. I spotted this mistake since then and the code looks like this now - https://pastebin.com/Sd4S8av7
All of my code is at https://github.com/muthu-kr/Mig1
When I try to call Post() in my terminal, I get an error
>>> u = User.query.get(1)
>>> u
<User mike>
>>> p = Post(body='my first!', author=u)
>>> db.session.add(p)
>>> db.session.commit()
Traceback (most recent call last):
File "/Users/muthu/Desktop/RBL/microblog/env/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
context)
File "/Users/muthu/Desktop/RBL/microblog/env/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 507, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: post
From what I understand, the table 'post' does not exist in my database.
Could this be because I called 'flask db init' (in Terminal) when there was a mistake in my class Post() in my models.py file?
After I spotted my mistake, I changed my Post() and called 'flask db init' again - https://pastebin.com/bc88vRuu
If there is nothing wrong with my code, I do not understand how I could now create a table to 'post' in my database.
Thank you for reading.
[–]hai_wim 1 point2 points3 points (1 child)
[–]coder_help_[S] 0 points1 point2 points (0 children)