0
class PubSquare(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    author_id = db.Column(db.Integer)
    subject = db.Column(db.String(60))
    timestamp = db.Column(db.DateTime, default=datetime.datetime.now())

the author_id is relation to class User.

publist = PubSquare.query.order_by(PubSquare.timestamp.desc()).all()

In jinja2,

{% for pub in publist %}
{{ pub.author_id }}
{% endfor %}

But I need to display the element in User. How Could I Do This?

I can't use foreignkey Because flask-migrate can't migrate models with foreignkeys. So I have to design models without foreignkeys.

I wish someone could help me, Thanks!

FeliceM
  • 4,163
  • 9
  • 48
  • 75
hugleecool
  • 205
  • 2
  • 9
  • 2
    You should be able to migrate a table with a foreign key so long as your migration doesn't cause an integrity error. – dirn Aug 24 '14 at 17:25
  • @dirm But I can't.If I use migrate, "NoReferencedTableError: Foreign key associated with column". But I can re-create the database with the same models. – hugleecool Aug 25 '14 at 07:17
  • What does your model look like when you try to use a foreign key? Can you also include the model it references? – dirn Aug 25 '14 at 13:00
  • @dirn I have new another question about it, could you see it ? http://stackoverflow.com/questions/25487475/flask-migrate-doesnt-work-when-i-add-models-with-foreignkey – hugleecool Aug 25 '14 at 13:53

0 Answers0