eve-sqlalchemy
eve-sqlalchemy copied to clipboard
Can't update a foreign key value
Hello!
I have a foreign key field: user = Column(Integer(), ForeignKey('clean_controller.id'))
When I try to make a PATCH/PUT request with the request body {"user": 11}
I get HTTP/1.0 422 UNPROCESSABLE ENTITY There is a clean_controller table and there is a row with id 11 in it. class CleanPoint(CommonColumns): tablename = 'clean_point' id = Column(Integer(), primary_key=True, autoincrement=True) ....
What is the correct way to update it?
The response body should contain more information on why the validation failed, can you provide that one, too?
One thing that could be the problem: you're referring to clean_controller but your example only contains clean_point.
Sorry. Copy-pasted incorrect class. class CleanController(CommonColumns): tablename = 'clean_controller' id = Column(Integer(), primary_key=True, autoincrement=True) name = Column(VARCHAR(30))
And the error is {"_issues": {"user": "unknown field"}, "_status": "ERR"}
After I removed FK from the field it works fine. I mean user = Column(Integer())
You'll need to add a relationship too, e.g. as in https://github.com/pyeve/eve-sqlalchemy/blob/master/examples/many_to_one/many_to_one/domain.py . At the moment plain ForeignKeys are not exposed by the API.