我将如何在 SQLAlchemy 和 Flask 中制作 Facebook 风格的消息传递系统(基于此http://www.9lessons.info/2013/05/message-conversation-database-design.html )?这是我目前的模型,但我不断收到不明确的外键错误,我假设基于我的对话表。
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
password = db.Column(db.String(12), unique=False)
conversation = db.relationship('Conversation',backref='user',lazy='dynamic')
conversation_reply = db.relationship('Conversation_Reply',backref='user',lazy='dynamic')
class Conversation(db.Model):
id = db.Column(db.Integer, primary_key=True)
user1 = db.Column(db.Integer, db.ForeignKey("user.id"))
user2 = db.Column(db.Integer, db.ForeignKey("user.id"))
timestamp = db.Column(db.DateTime)
conversation_reply = db.relationship('Conversation_Reply',backref='conversation',lazy='dynamic')
class Conversation_Reply(db.Model):
id = db.Column(db.Integer, primary_key = True)
reply = db.Column(db.Text)
user_id_fk = db.Column(db.Integer, db.ForeignKey("user.id"))
time = db.Column(db.DateTime)
c_id_fk = db.Column(db.String(11), db.ForeignKey("conversation.id"))