[web2py] IntegrityError('FOREIGN KEY constraint failed',)

2017-10-25 Thread mostwanted


*WHEN I TRY ENTERING A STUDENT'S DETAILS AND SELECTING THEIR GUARDIAN AS 
FROM THE DROP DOWN MENU AS REFERNCED I GET A FOREIGN CONSTRAINT FAILED 
ERROR MESSAGEMY TABLES*

db.define_table('guardian',
Field('surname', requires=IS_NOT_EMPTY()),
Field('name', requires=IS_NOT_EMPTY()),
Field('contact_number'),
format='%(surname)s')

db.define_table('student',
Field('surname', requires=IS_NOT_EMPTY()),
Field('name', requires=IS_NOT_EMPTY()),
Field('photo', 'upload', requires=IS_NOT_EMPTY()),
Field('guardian', 'reference guardian'),
Field('class_name', 'reference student_class'),
Field('dob', 'date', requires=IS_NOT_EMPTY()),
format='%(surname)s')

*MY CONTROLLER*

def show_students():
show_students=db(db.student).select(db.student.ALL)
return locals()



*MY VIEW*
SELECT A STUDENT TO VIEW THEIR PROFILE


SURNAME
NAME
CLASS
GUARDIAN

{{for students in show_students:}}

{{=A('VIEW', _class="glyphicon glyphicon-user", 
_href=URL('student_profile', args=students.id))}} | 
 {{=students.surname}}
{{=students.name}}
{{=students.class_name.class_name}}
{{=students.guardian.guardian}}

{{pass}}




*MY TRACEBACK ERROR*
 FOREIGN KEY constraint failed 



Traceback (most recent call last):
  File "/home/mostwanted/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
  File "/home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py" 
, line 
696, in 
  File "/home/mostwanted/web2py/gluon/globals.py", line 409, in 
self._caller = lambda f: f()
  File "/home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py" 
, line 
147, in insert
if form.accepts(request.vars, session):
  File "/home/mostwanted/web2py/gluon/sqlhtml.py", line 1862, in accepts
self.vars.id = self.table.insert(**fields)
  File "/home/mostwanted/web2py/gluon/packages/dal/pydal/objects.py", line 734, 
in insert
ret = self._db._adapter.insert(self, row.op_values())
  File "/home/mostwanted/web2py/gluon/packages/dal/pydal/adapters/base.py", 
line 486, in insert
raise e
IntegrityError: FOREIGN KEY constraint failed

Error snapshot [image: help] 

 

(FOREIGN KEY constraint failed) 

inspect attributes 
Frames 
   
   - 
   
   *File /home/mostwanted/web2py/gluon/restricted.py in restricted at line 
   219* code arguments variables 
   - 
   
   *File /home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py 
   in  at line 696* code arguments variables 
   - 
   
   *File /home/mostwanted/web2py/gluon/globals.py in  at line 409* 
   code arguments variables 
   - 
   
   *File /home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py 
   in insert at line 147* code arguments variables 
   - 
   
   *File /home/mostwanted/web2py/gluon/sqlhtml.py in accepts at line 1862* 
   code arguments variables 
   - 
   
   *File /home/mostwanted/web2py/gluon/packages/dal/pydal/objects.py in 
   insert at line 734* code arguments variables 
   - 
   
   *File /home/mostwanted/web2py/gluon/packages/dal/pydal/adapters/base.py 
   in insert at line 486* code arguments variables 
   Function argument list 
   
   (self=, table=, 
   fields=[(, 'Leburu'), (, 'Percy'), (, '2010-10-05'), 
   (, 5), (, 21), 
   (, 
   'student.photo.a21f46af61cba907.706963322e6a7067.jpg')])
   Code listing 
   
   481.
   482.
   483.
   484.
   485.
   486.
   
   487.
   488.
   489.
   490.
   
   self.execute(query)
   except:
   e = sys.exc_info()[1]
   if hasattr(table, '_on_insert_error'):
   return table._on_insert_error(table, fields, e)
   raise e
   
   if hasattr(table, '_primarykey'):
   pkdict = dict([
   (k[0].name, k[1]) for k in fields
   if k[0].name in table._primarykey])
   
   Variables 
   e IntegrityError('FOREIGN KEY constraint failed',) 
   
Context 

locals request session response 
In file: /home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py 

1.

 at 0xb6e606e0, file 
"/home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py", line 7>

-- 
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] IntegrityError: foreign key constraint failed

2014-11-19 Thread Богдан Ефименко
Hello
I do not know much English
I have two tables:

db.define_table('category', Field('name'))

db.define_table('books',
Field('title', requires=IS_NOT_EMPTY('Введите название 
книги'), label='Название*'),
Field('author', requires=IS_NOT_EMPTY('Введите автора'), 
label='Автор*'),
Field('god', 'integer', label='Год выпуска'),
Field('number_of_pages', 'integer', label='Количество 
страниц'),
Field('languages', label='Язык книги*'),
Field('category', 'reference category', label='Категория*'),
Field('description', 'text', label='Описание'),
Field('oblozhka', 'upload', label='Обложка'),
Field('book', 'upload', label='Файл книги*', 
requires=IS_NOT_EMPTY('Загрузите файл книги'))
)
But when i add a record to a table, I get an error:
IntegrityError: foreign key constraint failed
How to fix it?

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