Hello there,

I am getting despair on this problem after 6 hours now and I hope I can get 
some help here.
After creating 3 models of a legacy database, and adding a SQLFORM in my 
controller, I'm always getting the error message

<class 'gluon.contrib.pymysql.err.IntegrityError'> (1452, u'Cannot add or 
update a child row: a foreign key constraint fails (`immobilia`.`property`, 
CONSTRAINT `fk_property_adress` FOREIGN KEY (`propertyAdressID`) REFERENCES 
`adress` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)')

Here is the model definition

legacy_db.define_table('adress',
    Field('street','string', label='Street'),
    Field('postalcode','string', label='Postal Code'),
    Field('city','string', label='City'),
    migrate=False)

#--------
legacy_db.define_table('propertydata',
    Field('size','double', label='Size (in m²)'),
    Field('nbed','integer', label='# Bedrooms'),
    Field('nbath','integer', label='# Bathrooms'),
    Field('buildingheight','double', label='Building height (in m)'),
    Field('floor','integer', label='Floor'),
    Field('price','double', label='Price in €'),
    migrate=False)

#--------
legacy_db.define_table('property',
    Field('propertyAdressID','id', 'reference adress.id', writable=False, 
readable=False),
    Field('propertyDataID','id', 'reference propertydata.id', 
writable=False, readable=False),
    Field('propertyApproved','integer', default=0, writable=False, 
readable=False),
    migrate=False)


And this is what my controller looks like:

def index():
    form=SQLFORM.factory(legacy_db.adress, legacy_db.property, 
legacy_db.propertydata)
    if form.accepts(request.vars):
        id = 
legacy_db.adress.insert(**legacy_db.adress._filter_fields(form.vars))
        form.vars.adress = id
        id = 
legacy_db.propertydata.insert(**legacy_db.propertydata._filter_fields(form.vars))
        form.vars.propertydata = id
        id = 
legacy_db.property.insert(**legacy_db.property._filter_fields(form.vars))
        response.flash='Property added'
    else:
        response.flash='Error in adding'
    return dict(message="", form=form)

Can you tell me what I'm doing wrong? I just have no idea anymore and 
google doesn't help me anymore.

Greetings and thank you in advance.


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to