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

安稳与你 提交于 2019-11-27 19:36:31

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.

It might be also that field name is not pointing correctly:

class ThreadFrom(FlaskForm):

    title = StringField('title', [validators.Length(max=128)])
    author= StringField('author', [validators.Length(max=32)])
    timestamp = DateField()
    forum = SelectField()

Instead of forum should be forum_id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!