miguelgrinberg / REST-auth

Example application for my RESTful Authentication with Flask article.
http://blog.miguelgrinberg.com/post/restful-authentication-with-flask
MIT License
922 stars 337 forks source link

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: users #15

Closed lorenzmaresca closed 5 years ago

lorenzmaresca commented 5 years ago

Hi Miguel,

I have tried running your code in the same exact way you displayed it, but I continue getting an error when trying to send POST requests to update the database with a new user (p.s. I use the same exact curl request stated in the README.md).

Find below the error:

File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1997, in call return self.wsgi_app(environ, start_response) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app response = self.handle_exception(e) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request return self.view_functionsrule.endpoint File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/tests.py", line 88, in new_user if User.query.filter_by(username=username).first() is not None: File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2755, in first ret = list(self[0:1]) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2547, in getitem return list(res) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2855, in iter return self._execute_and_instances(context) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2878, in _execute_and_instances result = conn.execute(querycontext.statement, self._params) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 945, in execute return meth(self, multiparams, params) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 263, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1053, in _execute_clauseelement compiled_sql, distilled_params File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context context) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception exc_info File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 186, in reraise raise value.with_traceback(tb) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context context) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.id AS users_id, users.username AS users_username, users.password_hash AS users_password_hash \nFROM users \nWHERE users.username = ?\n LIMIT ? OFFSET ?'] [parameters: ('kseniya', 1, 0)]

miguelgrinberg commented 5 years ago

Make sure the db.create_all() call is running. If it is, then make sure your User model has been imported when db.create_all() run.

lorenzmaresca commented 5 years ago

Hi Miguel,

Thanks for the quick reply.

I was wondering if you had some indicative code that runs the same framework on CQLalchemy, not SQLalchemy. My aim is to not store user data locally but remotely.

All the best, Lorenz.

miguelgrinberg commented 5 years ago

@lorenzmaresca Unfortunately I do not have any examples based on Flask-CQLAlchemy. Sorry.

azarezade commented 5 years ago

@miguelgrinberg I have also the same issue running the exact files of the project. I also noticed db.create_all() in the code, it creates the db file but it seems there is no users table.

FLASK_APP = temp-auth.py
FLASK_ENV = development
FLASK_DEBUG = 0
In folder /Users/ali/GoogleDrive/Projects/CRM/crm-nlu
/anaconda3/bin/python -m flask run
 * Serving Flask app "temp-auth.py"
 * Environment: development
 * Debug mode: off
/anaconda3/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py:794: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2019-04-10 11:21:49,498] ERROR in app: Exception on /api/users [POST]
Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 507, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: users

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/anaconda3/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/ali/GoogleDrive/Projects/CRM/crm-nlu/temp-auth.py", line 70, in new_user
    if User.query.filter_by(username=username).first() is not None:
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2825, in first
    ret = list(self[0:1])
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2617, in __getitem__
    return list(res)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2925, in __iter__
    return self._execute_and_instances(context)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2948, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 948, in execute
    return meth(self, multiparams, params)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 269, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1060, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1200, in _execute_context
    context)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
    exc_info
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 186, in reraise
    raise value.with_traceback(tb)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 507, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.id AS users_id, users.username AS users_username, users.password_hash AS users_password_hash \nFROM users \nWHERE users.username = ?\n LIMIT ? OFFSET ?'] [parameters: ('miguel', 1, 0)] (Background on this error at: http://sqlalche.me/e/e3q8)
azarezade commented 5 years ago

Following this article, my problem solved using this:

@app.before_first_request
def create_tables():
    db.create_all()

in the main script instead of:

if __name__ == '__main__':
    if not os.path.exists('db.sqlite'):
        db.create_all()
miguelgrinberg commented 5 years ago

@azarezade you could have also solved the issue by deleting your db.sqlite file, which would force the db.create_all() call to run from its original place.

azarezade commented 5 years ago

@miguelgrinberg I tried and delete db.sqlite several times then restart the api, but it didn't solved the issue! I have also delete the whole project and clone it from github again. Anyway, thanks.

PengKuang commented 4 years ago

Following this article, my problem is solve using this:

@app.before_first_request
def create_tables():
    db.create_all()

in the main script instead of:

if __name__ == '__main__':
    if not os.path.exists('db.sqlite'):
        db.create_all()

Thank you. This worked for me!

Master1624 commented 3 years ago

Following this article, my problem is solve using this:

@app.before_first_request
def create_tables():
    db.create_all()

in the main script instead of:

if __name__ == '__main__':
    if not os.path.exists('db.sqlite'):
        db.create_all()

Thank you. This worked for me also!!

chiragbhuvaneshwara commented 3 years ago

@azarezade you could have also solved the issue by deleting your db.sqlite file, which would force the db.create_all() call to run from its original place.

Hi @miguelgrinberg . I tried this approach with Python 3.7 but it did not help. Just including db.create_all outside the name == 'main' condition is sufficient or as others have verified we can use @app.before_first_request . Don't really understand why this is happening though.

msm17b019 commented 3 years ago

Following this article, my problem is solve using this:

@app.before_first_request
def create_tables():
    db.create_all()

in the main script instead of:

if __name__ == '__main__':
    if not os.path.exists('db.sqlite'):
        db.create_all()

Thank You. You saved my time.

TonnyVega commented 2 years ago

Following this article, my problem is solve using this:

@app.before_first_request
def create_tables():
    db.create_all()

in the main script instead of:

if __name__ == '__main__':
    if not os.path.exists('db.sqlite'):
        db.create_all()

Thank You. I've been dealing with this issue for a few days, thank you.

EvandrooViegas commented 2 years ago

Hi Miguel,

I have tried running your code in the same exact way you displayed it, but I continue getting an error when trying to send POST requests to update the database with a new user (p.s. I use the same exact curl request stated in the README.md).

Find below the error:

File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1997, in call return self.wsgi_app(environ, start_response) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app response = self.handle_exception(e) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request return self.view_functionsrule.endpoint File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/tests.py", line 88, in new_user if User.query.filter_by(username=username).first() is not None: File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2755, in first ret = list(self[0:1]) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2547, in getitem return list(res) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2855, in iter return self._execute_and_instances(context) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2878, in _execute_and_instances result = conn.execute(querycontext.statement, self._params) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 945, in execute return meth(self, multiparams, params) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 263, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1053, in _execute_clauseelement compiled_sql, distilled_params File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context context) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception exc_info File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 186, in reraise raise value.with_traceback(tb) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context context) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.id AS users_id, users.username AS users_username, users.password_hash AS users_password_hash \nFROM users \nWHERE users.username = ?\n LIMIT ? OFFSET ?'] [parameters: ('kseniya', 1, 0)]

Hi Miguel,

I have tried running your code in the same exact way you displayed it, but I continue getting an error when trying to send POST requests to update the database with a new user (p.s. I use the same exact curl request stated in the README.md).

Find below the error:

File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1997, in call return self.wsgi_app(environ, start_response) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app response = self.handle_exception(e) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request return self.view_functionsrule.endpoint File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/tests.py", line 88, in new_user if User.query.filter_by(username=username).first() is not None: File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2755, in first ret = list(self[0:1]) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2547, in getitem return list(res) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2855, in iter return self._execute_and_instances(context) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2878, in _execute_and_instances result = conn.execute(querycontext.statement, self._params) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 945, in execute return meth(self, multiparams, params) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 263, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1053, in _execute_clauseelement compiled_sql, distilled_params File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context context) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception exc_info File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 186, in reraise raise value.with_traceback(tb) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context context) File "/Users/lorenzmaresca/Desktop/Cloud Computing/CCLab/Mini Project/flask_venv/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.id AS users_id, users.username AS users_username, users.password_hash AS users_password_hash \nFROM users \nWHERE users.username = ?\n LIMIT ? OFFSET ?'] [parameters: ('kseniya', 1, 0)]

Hello! I had the same issue, and what i did to solve the problem was delete the db file and create another one (db.creat_all) and import the class again

cobecode7 commented 1 year ago

Following this article, my problem is solve using this:

@app.before_first_request
def create_tables():
    db.create_all()

in the main script instead of:

if __name__ == '__main__':
    if not os.path.exists('db.sqlite'):
        db.create_all()

Thank You. I've been dealing with this issue for a few days, thank you.

SinaNajafi1 commented 5 months ago

Following this article, my problem solved using this:

@app.before_first_request
def create_tables():
    db.create_all()

in the main script instead of:

if __name__ == '__main__':
    if not os.path.exists('db.sqlite'):
        db.create_all()

This Worked Thanks!!!