I'm writing a signup/login script for Flask, and I am using flask-sqlalchemy. To sign a user up, I INSERT their details into the db through flask-sqlalchemy, then commit the change. However, when they try to login, which fetches their details from the db, I get a NoneType error, indicating that the entry I am trying to find is not present.
I am using MySQL 5.5 and the latest version of Flask and Flask-Sqlalchemy.
Error:
AttributeError: 'NoneType' object has no attribute 'password'
Code:
newuser = User(username='username', email='email', valid=1, password='hashpass', rkey=rkey, score=0, ip=uip)
db.session.add(newuser)
db.session.commit()
pwhash = User.query.filter_by(username='username').first().password
return str(pwhash)
Model
class User(db.Model):
__tablename__ = 'users'
uid = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(50))
password = db.Column(db.Text)
email = db.Column(db.String(120))
rkey = db.Column(db.String(50))
role = db.Column(db.String(20))
valid = db.Column(db.Boolean)
ip = db.Column(db.String(110))
lastip = db.Column(db.String(110))
score = db.Column(db.Integer)
def __repr__(self):
return '<User %r>' % self.username
print(db.query.all())and see if the database did anything with it? - corvidFile "<debugger>", line 1, in <module> print(db.query.all()) AttributeError: 'SQLAlchemy' object has no attribute 'query'. I setdb = SQLAlchemy()in the beginning of the app, not sure if that makes a difference. - bycUser.query.all()- corvid[<User u'cydrobolt'>, <User u'admin'> ...], but the new user I registered is not there. - byc