I work in a Python Eve-based RESTful service using SQLAlcemy. I have two models with a one to one relationship:
class User(CommonColumns): """Model of an user in the database""" __tablename__ = "user" id = Column(Integer, primary_key=True) username = Column(String, unique=True) email = Column(EmailType, unique=True) folders = relationship('Folder', backref='user') def __unicode__(self): return self.username class Folder(CommonColumns): """Model of an user in the database""" __tablename__ = "folder" id = Column(Integer, primary_key=True) name = Column(String, unique=True) user_id = Column(Integer, ForeignKey('user.id'), nullable=False) def __unicode__(self): return "{}/{}".format(self.user.username, self.name)
CommonColumns defined as here
This works great when inserting, updating, and deleting users . However, I cannot get the correct attachment for folders :
newfolder = { 'name':'FOLDER', 'user_id': 1, } response = requests.post("http://localhost:8080/api/v1.0/folders",data=newfolder) print response.json() {u'_error': {u'code': 422, u'message': u'Insertion failure: 1 document(s) contain(s) error(s)'}, u'_issues': {u'exception': u"'user'"}, u'_status': u'ERR'}
This is a rather cryptic error message. I read the Python Eve documentation and I cannot figure out what I'm doing wrong. The only difference that I see between user and folder inserts is that it has foreign keys.
Any idea why this is happening?
source share