尝试将ID更改为UUID之后,无法创建新数据库
我想我真的弄乱了一些东西...我试图用uuid更改烧瓶 - 塞格勒奇德表,我认为它不能转换为整数,因为在uuid中有-
,之后我都恢复了所有更改并通过删除旧数据库,然后创建一个新的数据库,从而返回使用id
。但是我仍然遇到与以前相同的错误
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120), unique=True, nullable=False)
image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
password = db.Column(db.String(60), nullable=False)
is_boss = db.Column(db.Boolean, nullable=False, default=False)
date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
posts = db.relationship('Post', backref='author', lazy=True)
cv3 = db.relationship('CVBase3', backref='author', lazy=True)
cv4 = db.relationship('CVBase4', backref='author', lazy=True)
cv5 = db.relationship('CVBase5', backref='author', lazy=True)
cv6 = db.relationship('CVBase6', backref='author', lazy=True)
cv7 = db.relationship('CVBase7', backref='author', lazy=True)
cv8= db.relationship('CVBase8', backref='author', lazy=True)
cv9 = db.relationship('CVBase9', backref='author', lazy=True)
worker = db.relationship('WorkerRegister', backref='author', lazy=True)
employer = db.relationship('Employer_Register', backref='author', lazy=True)
def get_reset_token(self, expires_sec=1800):
s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
return s.dumps({'user_id': self.id}).decode('utf-8')
@staticmethod
def verify_reset_token(token):
s = Serializer(current_app.config['SECRET_KEY'])
try:
user_id = s.loads(token)['user_id']
except:
return None
return User.query.get(user_id)
def __repr__(self):
return f"User('{self.email}', '{self.image_file}','{self.is_boss}', '{self.date_created}')"
,我遇到的错误 文件“ C:\ code2 \ flaskblog \ models.py”,第13行,在load_user return user.query.get(int(user_id))valueerror:Int()的INTARAL INTARAL:base 10:'12BE2F9B-F453 -43EB-B10E-9797CB3C657F'
I think I really messed something up... I tried to change my flask-sqlalchemy id table with UUID, I think it cant convert to integer since there is -
in the UUID, after that I reverted all changes and got back to using id
, by deleting old database, and just create a new one. but I'm still getting the same error as before
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120), unique=True, nullable=False)
image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
password = db.Column(db.String(60), nullable=False)
is_boss = db.Column(db.Boolean, nullable=False, default=False)
date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
posts = db.relationship('Post', backref='author', lazy=True)
cv3 = db.relationship('CVBase3', backref='author', lazy=True)
cv4 = db.relationship('CVBase4', backref='author', lazy=True)
cv5 = db.relationship('CVBase5', backref='author', lazy=True)
cv6 = db.relationship('CVBase6', backref='author', lazy=True)
cv7 = db.relationship('CVBase7', backref='author', lazy=True)
cv8= db.relationship('CVBase8', backref='author', lazy=True)
cv9 = db.relationship('CVBase9', backref='author', lazy=True)
worker = db.relationship('WorkerRegister', backref='author', lazy=True)
employer = db.relationship('Employer_Register', backref='author', lazy=True)
def get_reset_token(self, expires_sec=1800):
s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
return s.dumps({'user_id': self.id}).decode('utf-8')
@staticmethod
def verify_reset_token(token):
s = Serializer(current_app.config['SECRET_KEY'])
try:
user_id = s.loads(token)['user_id']
except:
return None
return User.query.get(user_id)
def __repr__(self):
return f"User('{self.email}', '{self.image_file}','{self.is_boss}', '{self.date_created}')"
and the error that I'm gettingFile "c:\code2\flaskblog\models.py", line 13, in load_user return User.query.get(int(user_id)) ValueError: invalid literal for int() with base 10: '12be2f9b-f453-43eb-b10e-9797cb3c657f'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论