AttributeError: 'int' object has no attribute '_sa_instance_state'

后端 未结 1 1269
情深已故
情深已故 2020-12-01 07:03

I\'m working on forum template using Flask. When I attempt creating a new thread in the browser using forms, SQLAlchemy throws an AttributeError. The problem showed up when

相关标签:
1条回答
  • 2020-12-01 07:43

    the problem is this:

    post = Post(body=form.body.data,
                timestamp=datetime.utcnow(),
                thread=thread.id,
                author=g.user.id)
    

    you want to work with ORM objects, not primary key columns:

    post = Post(body=form.body.data,
                timestamp=datetime.utcnow(),
                thread=thread,
                author=g.user)
    

    the error means that an integer is being interpreted as an ORM object.

    0 讨论(0)
提交回复
热议问题