评论功能,计划一条评论对应多个回复,但是看文档有些地方不太清楚
部分源码
class Comments(db.Model):
__tablename__ = 'comments'
id = db.Column(db.Integer,primary_key=True)
comment_user = db.Column(db.String, nullable=False)
comment_publish = db.Column(db.DateTime, nullable=False)
comment_content = db.relationship('Replies',backref='comments',lazy='dynamic')
def __init__(self, comment_user,comment_content, comment_publish = datetime.datetime.now()):
self.comment_user = comment_user
self.comment_content = comment_content
self.comment_publish = comment_publish
def __repr__(self):
return "<Comments %r>" % self.comment_content
class Replies(db.Model):
__tablename__ = 'replies'
id = db.Column(db.Integer,primary_key=True)
reply_user = db.Column(db.String, nullable=False)
reply_publish = db.Column(db.DateTime, nullable=False)
reply_content = db.Column(db.Text,nullable=False)
comments_id = db.Column(db.Integer, db.ForeignKey('comments.id'))
def __init__(self, reply_user,reply_content, reply_publish = datetime.datetime.now()):
self.reply_user = reply_user
self.reply_content = reply_content
self.reply_publish = reply_publish
def __repr__(self):
return "<Replies %r>" % self.reply_content
使用这个创建表后利用
all_comment = Comments.query.join(Replies).all()
查询,报错
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: comments [SQL: 'SELECT comments.id AS comments_id, comments.comment_user AS comments_comment_user, comments.comment_publish AS comments_comment_publish \nFROM comments JOIN replies ON comments.id = replies.comments_id']
确认已经创建表,请教大神这个应该怎么弄
部分源码
class Comments(db.Model):
__tablename__ = 'comments'
id = db.Column(db.Integer,primary_key=True)
comment_user = db.Column(db.String, nullable=False)
comment_publish = db.Column(db.DateTime, nullable=False)
comment_content = db.relationship('Replies',backref='comments',lazy='dynamic')
def __init__(self, comment_user,comment_content, comment_publish = datetime.datetime.now()):
self.comment_user = comment_user
self.comment_content = comment_content
self.comment_publish = comment_publish
def __repr__(self):
return "<Comments %r>" % self.comment_content
class Replies(db.Model):
__tablename__ = 'replies'
id = db.Column(db.Integer,primary_key=True)
reply_user = db.Column(db.String, nullable=False)
reply_publish = db.Column(db.DateTime, nullable=False)
reply_content = db.Column(db.Text,nullable=False)
comments_id = db.Column(db.Integer, db.ForeignKey('comments.id'))
def __init__(self, reply_user,reply_content, reply_publish = datetime.datetime.now()):
self.reply_user = reply_user
self.reply_content = reply_content
self.reply_publish = reply_publish
def __repr__(self):
return "<Replies %r>" % self.reply_content
使用这个创建表后利用
all_comment = Comments.query.join(Replies).all()
查询,报错
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: comments [SQL: 'SELECT comments.id AS comments_id, comments.comment_user AS comments_comment_user, comments.comment_publish AS comments_comment_publish \nFROM comments JOIN replies ON comments.id = replies.comments_id']
确认已经创建表,请教大神这个应该怎么弄