Python Forum
SQLAlchemy Flask ERROR: no such column XXX
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQLAlchemy Flask ERROR: no such column XXX
#1
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 269 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  SQLALCHEMY - Column doesn't exist jamesaarr 9 7,582 Nov-04-2021, 09:20 AM
Last Post: ndc85430
  Index error - columns vs non-column Vinny 3 4,924 Aug-09-2021, 04:46 PM
Last Post: snippsat
  [gpxpy] "Error parsing XML: not well-formed (invalid token): line 1, column 1" Winfried 5 6,689 Jan-26-2020, 01:09 AM
Last Post: Winfried
  selecting a particular column in csv file shows error raady07 7 4,274 Mar-15-2018, 02:19 PM
Last Post: Larz60+
  error while inserting values into a table from form in flask in postgreSQL sahilsiddharth 3 7,157 Jun-05-2017, 07:49 PM
Last Post: sahilsiddharth

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020