[web2py] Re: Beginner question: foreign key constraint failed (?)

2014-03-28 Thread Krzysztof Socha
On Thursday, March 27, 2014 5:21:34 PM UTC+1, Niphlod wrote:

 did you try with a fresh database ?


After some investigation, it seems that the problem is not related to what 
I wrote above (!)

I tried to change the DB - to MySQL - and the error reported changed to 
something like 'attribute first_name not found'. From this I managed to 
understand what happens. 

In fact, the 'company' table is redefining auth_user table. However, it 
seems that (contrary to the documentation) the 'first_name' field is needed 
by the default implementation of the NavBar. And hence the error. It is 
weird that SQLite reports it as foreign constraint failed... Or maybe 
indeed there was something wrong with the SQLite database in the first 
place...

Anyway... The conclusion is - the code I gave above actually works.

-- 
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.


[web2py] Re: Beginner question: foreign key constraint failed (?)

2014-03-28 Thread Krzysztof Socha
Just an update. It appears to be an issue with SQLITE. The actual problem 
was related to the fact that I have redefined AUTH_USER table (by company 
table - not all of it quated in my post). I had a missing field used in the 
default NavBar - first_name. When I switched from SQLITE to MYSQL, the 
error message was more informative - somthing about missing attribute 
'first_name'. This led in turn to discovering that in fact the 'first_name' 
is kind of required field when redefining the AUTH_USER table, even though 
the documentation does not say so

Hope it will help others. 

BTW: The error message from SQLITE could be improved... 

-- 
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.


[web2py] Re: Beginner question: foreign key constraint failed (?)

2014-03-27 Thread Niphlod
did you try with a fresh database ?

On Thursday, March 27, 2014 3:18:07 PM UTC+1, Krzysztof Socha wrote:

 I created a simple table that uses another table as a list of possible 
 values for a field:

 db.define_table('country',
 Field('name','string',length=DEFAULT_STRING_LENGTH))

 db.define_table('company',
 Field('name', 'string',
 requires=IS_NOT_EMPTY(error_message=auth.messages.is_empty)),
 Field('address', 'string',
 Field('country','reference country',
 requires=IS_IN_DB(db,db.country.id)))

 This is all very simplistic, and I just want to have the ID in the 
 dropdown (later to be replaced by something like 'represent=
 db.country.name(db.country.id))', but it does not work as it is...

 The form shows up, I need to put something in the NAME field and choose 
 something for the COUNTRY field - otherwise the validators complain - but 
 aftwerwords I systematically get:

 class 'sqlite3.IntegrityError' foreign key constraint failed


-- 
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.