Почему я получаю ошибку, нет такого столбца: AW в моем коде?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Почему я получаю ошибку, нет такого столбца: AW в моем коде?

Сообщение Anonymous »

Я получаю эту ошибку из своего кода: < /p>
[2025-04-28 16:24:58,421] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\engine\base.py", line 1964, in _exec_single_context
self.dialect.do_execute(
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\engine\default.py", line 945, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: no such column: users.aw

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

Traceback (most recent call last):
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask\app.py", line 1511, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask\app.py", line 919, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask\app.py", line 917, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask\app.py", line 902, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\theco\OneDrive\Documents\veil\app.py", line 31, in index
@app.route('/index')
^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask\templating.py", line 150, in render_template
return _render(app, template, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask\templating.py", line 127, in _render
app.update_template_context(context)
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask\app.py", line 530, in update_template_context
context.update(self.ensure_sync(func)())
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask_login\utils.py", line 405, in _user_context_processor
return dict(current_user=_get_user())
^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask_login\utils.py", line 370, in _get_user
current_app.login_manager._load_user()
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\flask_login\login_manager.py", line 364, in _load_user
user = self._user_callback(user_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\theco\OneDrive\Documents\veil\app.py", line 51, in loader_user
@login_manager.user_loader
^^^^^^^^^^^^^^^^
File "", line 2, in get
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\util\deprecations.py", line 386, in warned
return fn(*args, **kwargs) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\orm\query.py", line 1126, in get
return self._get_impl(ident, loading.load_on_pk_identity)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\orm\query.py", line 1135, in _get_impl
return self.session._get_impl(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\orm\session.py", line 3874, in _get_impl
return db_load_fn(
^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\orm\loading.py", line 694, in load_on_pk_identity
session.execute(
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\orm\session.py", line 2365, in execute
return self._execute_internal(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\orm\session.py", line 2251, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\orm\context.py", line 306, in orm_execute_statement
result = conn.execute(
^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\engine\base.py", line 1416, in execute
return meth(
^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\sql\elements.py", line 523, in _execute_on_connection
return connection._execute_clauseelement(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\engine\base.py", line 1638, in _execute_clauseelement
ret = self._execute_context(
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\engine\base.py", line 1843, in _execute_context
return self._exec_single_context(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\engine\base.py", line 1983, in _exec_single_context
self._handle_dbapi_exception(
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\engine\base.py", line 2352, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\engine\base.py", line 1964, in _exec_single_context
self.dialect.do_execute(
File "C:\Users\theco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\sqlalchemy\engine\default.py", line 945, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: users.aw
[SQL: SELECT users.id AS users_id, users.username AS users_username, users.password AS users_password, users.location AS users_location, users.aw AS users_aw, users.ms AS users_ms, users.sa AS users_sa
FROM users
WHERE users.id = ?]
[parameters: ('2',)]
(Background on this error at: https://sqlalche.me/e/20/e3q8)
< /code>
my code: < /p>
import os
from flask import Flask, render_template, redirect, url_for, request, jsonify
from flask_login import LoginManager, UserMixin, login_user, current_user
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///db.sqlite"
app.secret_key = 'kevin2000'
app.config['SESSION_TYPE'] = 'filesystem'

db = SQLAlchemy(app)

class Users(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(250), unique=True, nullable=False)
password = db.Column(db.String(250), nullable=False)
location = db.Column(db.String(250), nullable=False)
aw = db.Column(db.String(250), nullable=False)
ms = db.Column(db.String(250), nullable=False)
sa = db.Column(db.String(250), nullable=False)

login_manager = LoginManager(app)

app.app_context().push()
with app.app_context():
db.drop_all()
db.create_all()

@app.route('/')
@app.route('/index')
def index():
return render_template('index.html')

@app.route('/', methods=["POST"])
@app.route('/index', methods=["POST"])
def recieveInfo():
data = request.get_json()
db.session.query(Users).filter_by(username=request.args.get('username')).update(dict(aw=data.aw, ms=data.ms, sa=data.sa))
db.session.commit()

@app.route('/cart')
def cart():
return render_template('cart.html')

@app.route('/delivery')
def delivery():
return render_template('delivery.html')

@login_manager.user_loader
def loader_user(user_id):
return Users.query.get(user_id)

@app.route('/register', methods=["GET", "POST"])
def register():

if request.method == "POST":
if not db.session.query(Users).filter_by(username=request.form.get("uname")).count() < 1:
return render_template("sign_up.html", value = "USER ALREADY EXISTS")
if request.form.get("uname") == "":
return render_template("sign_up.html", value = "USERNAME IS BLANK")
if request.form.get("psw") == "":
return render_template("sign_up.html", value = "PASSWORD IS BLANK")
if request.form.get("loc") == "":
return render_template("sign_up.html", value = "LOCATION IS BLANK")
user = Users(username=request.form.get("uname"),
password=request.form.get("psw"),
location=request.form.get("loc"),
aw="0",
ms="0",
sa="0")

db.session.add(user)
db.session.commit()

return redirect(url_for("login"))

return render_template("sign_up.html")

@app.route("/login", methods=["GET", "POST"])
def login():
if current_user.is_authenticated:
return redirect(url_for("index", logged_in = True, username = current_user.username))

if request.method == "POST":
user = Users.query.filter_by(
username=request.form.get("uname")).first()
if not user:
return render_template("login.html", value = request.form.get("uname"))

if user.password == request.form.get("psw"):
login_user(user)
return redirect(url_for("index", username = user.username))
return render_template("login.html")

if __name__ == "__main__":
app.run(host ="0.0.0.0", port = 10000, debug=False)

< /code>
Как вы можете видеть, я попробовал db.drop_all () и app.app_context.push ()
, но, кажется, не работает
im также довольно новичок в колбе, и я стараюсь часами < /p>
Я искал в других местах и ​​пытался интегрировать растворы, но он не сработал < /p>
, если он не помогал, я не старался. Файл также

Подробнее здесь: https://stackoverflow.com/questions/795 ... in-my-code
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»