I'm trying to store a user and password in a table I created with sqlite db. It seems that pwd column doesn't exist, while if I check the table in sqlite it does contain the column.
The error returns the following:
sqlalchemy.exc.OperationalError
OperationalError: (sqlite3.OperationalError) table user has no column named pwd
[SQL: INSERT INTO user (id, username, pwd) VALUES (?, ?, ?)]
[parameters: (1, 'ita_itf', '$2b$12$j5NPKCgv8DsFnOJtHE2xjOyXMoGSFCz89Gf/Oy2Hs.FfEx/0BuOY2')]
(Background on this error at: http://sqlalche.me/e/e3q8)
ERROR DETAILS:
File "/home/itad/DICP_evo_dev/venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 552, in do_execute
def do_executemany(self, cursor, statement, parameters, context=None):
cursor.executemany(statement, parameters)
def do_execute(self, cursor, statement, parameters, context=None):
cursor.execute(statement, parameters)
def do_execute_no_params(self, cursor, statement, context=None):
cursor.execute(statement)
def is_disconnect(self, e, connection, cursor):
this is the User class I created:
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data-users.sqlite'
bcrypt = Bcrypt(app)
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ = "user"
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,id,username,pwd):
self.id=id
self.username = username
self.pwd = bcrypt.generate_password_hash(pwd)
This is the code where I manually insert the password with a python GUI in my app:
from store_user_db import User, db
DICP_FTP_DESTINATION_PSW=self.submit_pwd()
user = User(id=001,username="ita_itf", pwd=DICP_FTP_DESTINATION_PSW)
db.session.add(user)
db.session.commit()
Here I check the user table if exist and the schema, I also tried to run sqlite>SELECT * FROM user but it doesn't return any result
itad@itad-virtual-machine:~/DICP_evo_dev$ sqlite3 data-users.sqlite
SQLite version 3.22.0 2018-01-22 18:45:57
Enter ".help" for usage hints.
sqlite> .schema user
CREATE TABLE user (
id INTEGER NOT NULL,
username VARCHAR,
pwd VARCHAR,
PRIMARY KEY (id),
UNIQUE (username)
);
Maybe it's easier if I show you the screenshots, the commented part is the one I used to create the table, then I commented it because you only need to create it once.
I didn't put that in the code but I previously did create the db and the table with the function table() then create_all() etc.. Then I comment that out. indeed if I type sqlite> .schema user, it shows the table, should be there in the db no?