Python Forum
Problem with storing data in SQLAlchemy db
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with storing data in SQLAlchemy db
#1
Hi there! I need urgent help, I have been stuck on this for days now.
My app needs the FTP password to ftp some file to another PC, I can't write the static password in the code so I have to encrypt it and store it in a db, SQLAlchemy in this case.
It returns the following error though:

sqlalchemy.exc.OperationalError

OperationalError: (sqlite3.OperationalError) table user has no column named pwd
[SQL: INSERT INTO user (username, pwd) VALUES (?, ?)]
[parameters: ('ita_itf', '$2b$12$IqFjS8XRxNiUDtJ4LFMUn.PNEF3VRT1fev57Bqjgh3VV/HX16ew.W')]
I have implemented the following class User that should (in theory) create a table with 3 columns in an existing db.

store_user_db.py:

import os
basedir = os.path.abspath(os.path.dirname(__file__))

from flask import Flask 
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')
bcrypt = Bcrypt(app)
db = SQLAlchemy(app)


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))

    def __init__(self,username,pwd):
        #self.id=id
        self.username=username
        self.pwd=bcrypt.generate_password_hash(pwd)
here in the application I import the class objects to store the user and password in the db table but somehow it doesn't find the column pwd. Any idea why?

        
        from store_user_db import User, db
        DICP_FTP_DESTINATION_PSW=self.submit_pwd()

        user = User(username="ita_itf", pwd=DICP_FTP_DESTINATION_PSW)
        db.session.add(user)
        db.session.commit()
Reply
#2
read this part of Miguel Grinberg's Flask mega tutorial: https://blog.miguelgrinberg.com/post/the...ser-logins
which has to do with logging in, out and user password storage.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SQLALCHEMY - Not selecting data from table jamesaarr 4 2,178 Nov-02-2021, 03:02 PM
Last Post: Larz60+
  Help with storing temp data for each day then recording min/max in app. trthskr4 3 2,359 Sep-10-2021, 10:51 PM
Last Post: trthskr4
  Looking for data/info on a perticular data-proccesing problem. MvGulik 9 3,780 May-01-2021, 07:43 AM
Last Post: MvGulik
  Storing MySQL BIT Data Type data in python variable krushna 2 3,433 Dec-31-2018, 01:28 AM
Last Post: krushna
  Storing Python data output as a Netcdf file Lightning1800 1 2,607 May-16-2018, 10:14 PM
Last Post: micseydel
  Problem with serial data. How do I ignor incorrect data? donmerch 1 2,892 Jul-11-2017, 01:55 AM
Last Post: donmerch
  Taking user input and storing that to a variable then storing that variable to a list jowalk 12 37,243 Mar-27-2017, 11:45 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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