Dear fellow w2p users,
First, thank you so much for providing this great app Web2Py for *free*.
Recently I updated my app to allow user to delete account themselves.
auth.settings.allow_delete_accounts= True
Today, I received feedback from user that that function is broken on my
site.
Then I realize there is a ticket when that function is called.
<class 'sqlite3.IntegrityError'> FOREIGN KEY constraint failed
Version
web2py™ Version 2.13.4-stable+timestamp.2015.12.26.04.59.39
Python Python 2.7.11:
/home/liuyidh/.pyenv/versions/miniconda-3.16.0/bin/python (prefix:
/home/liuyidh/.pyenv/versions/miniconda-3.16.0)
Traceback
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Traceback (most recent call last):
File "/home/liuyidh/lovelovebean.com/gluon/restricted.py", line 227, in
restricted
exec ccode in environment
File
"/home/liuyidh/lovelovebean.com/applications/LLBean/controllers/default.py"
<http://127.0.0.1:8001/admin/edit/LLBean/controllers/default.py>, line 97, in
<module>
File "/home/liuyidh/lovelovebean.com/gluon/globals.py", line 412, in <lambda>
self._caller = lambda f: f()
File
"/home/liuyidh/lovelovebean.com/applications/LLBean/controllers/default.py"
<http://127.0.0.1:8001/admin/edit/LLBean/controllers/default.py>, line 55, in
user
return dict(form=auth(), formFil=formFil)
File "/home/liuyidh/lovelovebean.com/gluon/tools.py", line 1923, in __call__
return getattr(self, args[0])()
File "/home/liuyidh/lovelovebean.com/gluon/tools.py", line 4025, in profile
self.log_event(log, self.user)
File "/home/liuyidh/lovelovebean.com/gluon/tools.py", line 2521, in log_event
origin=origin, user_id=user_id)
File "/home/liuyidh/lovelovebean.com/gluon/packages/dal/pydal/objects.py",
line 731, in insert
ret = self._db._adapter.insert(self, self._listify(fields))
File
"/home/liuyidh/lovelovebean.com/gluon/packages/dal/pydal/adapters/base.py",
line 746, in insert
raise e
IntegrityError: FOREIGN KEY constraint failed
I searched stackoverflow for tips. It seems the causes are different. Some
are due to migration, some due to wrong reference, others due to auth().
I have a user form in the profile page:
def user():
if request.args(0)=='profile':
db.auth_criteria.user_id.default = auth.user_id
record = db.auth_criteria(db.auth_criteria.user_id==auth.user_id)
formFil=SQLFORM(db.auth_criteria,
record=record,
labels = {'salePrice':XML('<h3>TWO-A-DAY Clothing & Home
Goods</h3> (By Sale Price)'),
'tgPrice':XML('<h3>ONE-A-DAY Travel and Gear </h3>
(By Sale Price)'),
'aveRev':XML('<b>By Avereage Ratings</b>'),
'percSave':XML('<b>By Percentage Saved</b>'),
'genderPref':XML('<h3>By Gender of Products</h3>
AND-gate. Other filters apply')
},
buttons = [TAG.button('Set Mine', _class='btn-primary')])
if formFil.process().accepted:
response.flash = XML('Your preference is recorded. <br>Get
ready for lovely beans.')
return dict(form=auth(), formFil=formFil)
else:
return dict(form=auth())
I have a custom defined table:
db.define_table('auth_criteria',
Field <http://127.0.0.1:8001/examples/global/vars/Field>('user_id',
'reference auth_user', readable=False, writable=False),
Field <http://127.0.0.1:8001/examples/global/vars/Field>('salePrice',
'integer', widget=SQLFORM
<http://127.0.0.1:8001/examples/global/vars/SQLFORM>.widgets.radio.widget,
requires = IS_IN_SET
<http://127.0.0.1:8001/examples/global/vars/IS_IN_SET>(salePrice)),
Field <http://127.0.0.1:8001/examples/global/vars/Field>('tgPrice',
'integer', widget=SQLFORM
<http://127.0.0.1:8001/examples/global/vars/SQLFORM>.widgets.radio.widget,
requires = IS_IN_SET
<http://127.0.0.1:8001/examples/global/vars/IS_IN_SET>(tgPrice)),
Field <http://127.0.0.1:8001/examples/global/vars/Field>('aveRev',
'integer', requires = IS_IN_SET
<http://127.0.0.1:8001/examples/global/vars/IS_IN_SET>(aveRev)),
Field <http://127.0.0.1:8001/examples/global/vars/Field>('percSave',
'integer', requires = IS_IN_SET
<http://127.0.0.1:8001/examples/global/vars/IS_IN_SET>(percSave)),
Field
<http://127.0.0.1:8001/examples/global/vars/Field>('genderPref','integer',
widget=SQLFORM
<http://127.0.0.1:8001/examples/global/vars/SQLFORM>.widgets.radio.widget,
requires = IS_IN_SET
<http://127.0.0.1:8001/examples/global/vars/IS_IN_SET>(genderPref)),
Field <http://127.0.0.1:8001/examples/global/vars/Field>('toSend','integer',
readable=False, writable=False))
# db.auth_criteria.user_id.requires = IS_IN_DB(db, db.auth_user.id)
db.auth_criteria.id.readable=False
## after defining tables, uncomment below to enable auditing
auth.enable_record_versioning(db)
I tried to comment the 9th "requires" line. Because in one SO answer
<http://stackoverflow.com/questions/28581755/web2py-sqlite3-integrityerrorforeign-key-constraint-failed>,
Anthony said it's not necessary. But It didn't help here.
My db line:
db = DAL
<http://127.0.0.1:8001/examples/global/vars/DAL>('sqlite://storage.sqlite',pool_size=1,check_reserved=['all'])
I tried migration before due to database errors. Is it the problem?
Thanks for any help.
Best, Yi
--
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.