SQLAlchemy Flask ERROR: no such column XXX - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: SQLAlchemy Flask ERROR: no such column XXX (/thread-29387.html) |
SQLAlchemy Flask ERROR: no such column XXX - marcello86 - Aug-31-2020 Hi there I'm trying to store a password in the db with SQLAlchemy, it's an FTP password that the application needs to submit some file, I was keeping the static pw in the code but for security reasons I cannot keep it in there, need to store it in the db. Here's the error: OperationalError: (sqlite3.OperationalError) no such column: user.pwd [SQL: SELECT user.id AS user_id, user.username AS user_username, user.pwd AS user_pwd FROM user] (Background on this error at: http://sqlalche.me/e/e3q8) ------------------------------------------------------------- Here I create the table with columns in the db which already exists, and encrypt the password with bcrypt #store_user_db.py import os basedir = os.path.abspath(os.path.dirname(__file__)) from flask import Flask from flask_sqlalchemy import SQLAlchemy from sqlalchemy.ext.automap import automap_base app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite') db = SQLAlchemy(app) Base = automap_base() Base.prepare(db.engine, reflect=True) User = Base.classes.user class User(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(64), unique=True) pwd = db.Column(db.String(128)) #db.create_all() ??????? <-- Not sure about this if must be included or not #@hybrid_property def password(self): return self.pwd #@password.setter def _set_password(self, plaintext): self.pwd = bcrypt.generate_password_hash(plaintext)-------------------------------------------------------------- Here I should store the password (I input the pw in the application with a GUI interface in python). Basically after I have stored it, I won't need this code again, I think I can make it run once and then delete the code? after has been stored I just need to retrieve the pw. Anyway I don't get this error, someone can help? #installment_form.py from store_user_db import User, db #GUI password input DICP_FTP_DESTINATION_PSW=self.submit_pwd() user = User(username="ita_itf", pwd=DICP_FTP_DESTINATION_PSW) db.session.add(user) db.session.commit() results = db.session.query(User).all() flash(results) for r in results: print(r.username) |