How are you generating the URL to access eintrag_erstellen, and are you 
sure the integer you are using in the URL is in fact the record ID of one 
of the records in db.category?

Anthony

On Tuesday, January 10, 2017 at 6:07:17 PM UTC-5, pilzsu...@emailn.de wrote:
>
> Good day,
>
> I was following the video tutorial of Massimo, just as other users here. 
> But when I want to submit a post I get the error
> >IntegrityError: foreign key constraint failed<
>
> -----------My db.py:-----------
>
> db.define_table('category', 
> Field('name',requires=IS_IN_SET(['suess','sauer','frostig','fruchtig','schokoladig','einfach_lecker'])))
>
> db.define_table('eintrag',
>                 Field('category','reference category',writable=False),
>                 Field('eintragId', 
> 'integer',readable=False,writable=False),
>                 Field('standort','string',requires=IS_NOT_EMPTY()),
>                 Field('laden','string'),
>                 Field('eis', 
> requires=IS_IN_SET(['Schokolade','Vanille','Erdbeere','Pistazie','Banane','Andere',])),
>                 Field('eigenschaft','text'),
>                 auth.signature)
>
> -----------My default.py:-----------
>
> def get_category():
>     category_name = request.args(0)
>     category = db.category(name=category_name)
>     if not category:
>         session.flash = 'Element nicht gefunden'
>         redirect(URL('eis'))
>     return category
>
> def eintrag_erstellen():
>     category = get_category()
>     db.eintrag.category.default = category.id
>     form = SQLFORM(db.eintrag).process(next='eintrag_betrachten/[id]')
>     return locals()
>
> -----------My view:-----------
>
> {{extend 'layout.html'}}
>
> {{block header}}
>  <link rel="stylesheet" href="{{=URL('static','css/style.css')}}"/>
> {{end}}
>
> <h2>
>     Erstelle einen neuen Beitrag über das Thema {{=category.name.title()}}
> </h2>
>
> </br>
>
> {{=form}}
>
>
>
> -----
> this is exactly the same code as massimo used (just with german words 
> instead of english ones, but this does not cause the problem). I already 
> found threads about this problem and their solution was to create tabled 
> with appadmin. I did. But the same error. 
> If I delete the row in default.py >db.eintrag.category.default = 
> category.id< everything works just fine but the fact that the category 
> field is "None". 
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to