Make sure you define it as a reference field, and then you can set 
notnull=True -- in that case, the database will not all NULL values in that 
field. Also, you can always set up database constraints outside of web2py 
using other database clients to alter table definitions.

Anthony

On Monday, March 10, 2014 3:34:17 AM UTC-4, Dan Why wrote:
>
> Okay, so the doc clearly says the validators are for input field 
> validations (chapter 7). What would be the recommended way to add 
> referential integrity check for the database to avoid something like what I 
> described? Also I am currently using SQLite (and I realize the result will 
> vary depending on the database). 
>
> Thanks,
> Dan
>
>
> On Thursday, March 6, 2014 11:41:12 PM UTC-8, Dan Why wrote:
>>
>> Hi all, 
>>
>> Working through the official documentation on Chapter 3, on Image blog 
>> example.
>>
>> in models.db.py
>> db.define_table('image', ...)
>> db.define_table('post', ...)
>> ...
>>
>> db.post.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
>>
>>
>> in controllers/default.py
>>
>> def show():
>>     image = db.image(request.args(0,cast=int)) or redirect(URL('index'))    
>> db.post.image_id.default = image.id  # <--- this line
>>  ...
>>
>>
>> I tried removing the line (db.post.image_id.default = image.id), and 
>> used the non-admin page to insert comments. The comments are inserted into 
>> DB. On admin page, post.image_id of those comments would show as None. This 
>> is somewhat surprising to me as I thought they were enforcing referencial 
>> integrity at DB level. It seems the validatiors are merely for front-end 
>> validation at form level. Is that correct? If so, does web2py have a way to 
>> enforce DB level validation? 
>>
>> Thanks,
>> Dan
>>
>

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