Foreign key definition is Field('parent_id', db.parent)
I have changed the requires= clause of the foreign key.
And now, later, all works well, regardless if I run without requires= or 
with requires=IS_IN_DB(db, db.parent.id).
So, I cannot repeat the error now.

But !

When I stay logged in and delete the SQLite database (all files in 
databases/),
then at next access I receive same error "foreign key constraint failed" 
with this stack (-- from auth.logout()):

2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.

Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\web2py_2_8_2\web2py\gluon\restricted.py", 
line 217, in restricted
    exec ccode in environment
  File 
"C:/Python27/Lib/site-packages/web2py_2_8_2/web2py/applications/edga/controllers/default.py"
 <http://localhost:8000/admin/default/edit/edga/controllers/default.py>, line 
88, in <module>
  File "C:\Python27\Lib\site-packages\web2py_2_8_2\web2py\gluon\globals.py", 
line 372, in <lambda>
    self._caller = lambda f: f()
  File 
"C:/Python27/Lib/site-packages/web2py_2_8_2/web2py/applications/edga/controllers/default.py"
 <http://localhost:8000/admin/default/edit/edga/controllers/default.py>, line 
10, in logout
    return dict(form=auth.logout())
  File "C:\Python27\Lib\site-packages\web2py_2_8_2\web2py\gluon\tools.py", line 
2422, in logout
    self.log_event(log, self.user)
  File "C:\Python27\Lib\site-packages\web2py_2_8_2\web2py\gluon\tools.py", line 
1879, in log_event
    origin=origin, user_id=user_id)
  File "C:\Python27\Lib\site-packages\web2py_2_8_2\web2py\gluon\dal.py", line 
9003, in insert
    ret =  self._db._adapter.insert(self, self._listify(fields))
  File "C:\Python27\Lib\site-packages\web2py_2_8_2\web2py\gluon\dal.py", line 
1311, in insert
    raise e
IntegrityError: foreign key constraint failed


So I think that problematical state occurs after:
- we take data from older web2py version
-or-
- we delete the sqlite database with goal to recreate it empty
If so, there is really no big problem - deleting sessions is enough in both 
cases (or in all cases when I do something non standard with the SQLite 
database).

Hopefuly it is so and there is no other problem inside 2.8.2




Dne čtvrtek, 13. února 2014 20:47:37 UTC+1 Cliff Kachinske napsal(a):
>
> Can you post the entire field definition for the foreign key field?
>
> On Thursday, February 13, 2014 12:39:26 PM UTC-5, Mirek Zvolský wrote:
>>
>> I have similar troubles as here:
>>
>> https://groups.google.com/forum/?fromgroups#!searchin/web2py/smartgrid$20foreign$20key$20constraint$20failed%7Csort:relevance%7Cspell:false/web2py/klspqXpha4E/mCwQ6HC5IhAJ
>>
>> I just have smartgrid, 1 parent table (main table for smartgrid), 1 child 
>> table. At the child foreign key I have standard requires=IS_IN_DB(db, 
>> db.parent.id)
>>
>> In parent table I have just first record, child table is completly empty. 
>> Now I navigate through the link in smartgrid row (of the single parent 
>> record) and try add the first record into child table.
>> This fails with
>> foreign key constraint failed
>>
>> Solution
>> adapter_args=dict(foreign_keys=False)
>> in DAL() works for me.
>>
>> But, can I repair it better?
>>
>

-- 
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/groups/opt_out.

Reply via email to