I added data to sqlite using sqlalchemy.
Only some data (in this case, password_hash) is not added and becomes null.
I'm reviewing it myself, but I can't find any mistakes.
Please point out any mistakes and advise me.
#app.py
importos
from flash import Flash
from flash_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config ['SECRET_KEY'] = 'mysecretkey'
app.config ['SQLALCHEMY_DATABASE_URI'] = 'sqlite://data.sqlite'
app.config ['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class User (db.Model):
__tablename__='users'
id=db.Column(db.Integer, primary_key=True)
email=db.Column(db.String(64), unique=True, index=True)
username=db.Column (db.String(64), unique=True, index=True)
password_hash = db.Column(db.String(128))
def__init__(self, email, username, password_hash):
self.email=email
self.username=username
self.password_hash
def__repr__(self):
returnf "UserName: {self.username}"
if__name__=='__main__':
app.run(debug=True)
#init_user.py
from app import db, User
db.create_all()
user1 = User("[email protected]", "Test user1", "111")
user2=User("[email protected]", "Test user2", "222")
db.session.add_all ([user1, user2])
db.session.commit()
print(user1.id)
print(user2.id)
The presentation code does not substitute the argument password_hash
value.
You may want to modify it as follows:
def_init__(self, email, username, password_hash):
self.email=email
self.username=username
self.password_hash=password_hash#***
708 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
549 PHP ssh2_scp_send fails to send files as intended
548 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
534 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.