Hi
have a problem with n:m relationships
My problem is that I can not add items to a table, which contains 2
primary keys (foreign keys)
Imagine I have two tables like

db.define_table('language',
    Field('name','string(50)', notnull=False, default=None),
    Field('rfc_code','string(10)', notnull=True, default=None),
    migrate=False)

db.define_table('country',
    Field('name','string(100)', notnull=True, default=None),
    Field('iso_code','string(8)', notnull=True, default=None),
    migrate=False)

I create a n:m connection with the table

db.define_table('country_has_language',
     Field('country_id', db.country, notnull=True, default=None),
     Field('language_id', db.language, notnull=True, default=None),
     primarykey=['country_id','language_id'],
     migrate=False)

db.country_has_language.country_id.requires=IS_IN_DB(db,'country.id','country.name')
db.country_has_language.language_id.requires=IS_IN_DB(db,'language.id','language.name')

If I want to add new items (n:m relation ships) I get an error
message:

Traceback (most recent call last):
  File "C:\web2py\gluon\restricted.py", line 188, in restricted
    exec ccode in environment
  File "C:/web2py/applications/App/controllers/appadmin.py", line 412,
in <module>
  File "C:\web2py\gluon\globals.py", line 124, in <lambda>
    self._caller = lambda f: f()
  File "C:/web2py/applications/App/controllers/appadmin.py", line 127,
in insert
    if form.accepts(request.vars, session):
  File "C:\web2py\gluon\sqlhtml.py", line 1186, in accepts
    pk = self.table.insert(**fields)
  File "C:\web2py\gluon\dal.py", line 4341, in insert
    return self._db._adapter.insert(self,self._listify(fields))
  File "C:\web2py\gluon\dal.py", line 760, in insert
    raise e
InternalError: (1048, u"Column 'country_id' cannot be null")

I think this is not a wanted behavior? Isn't it.

Thanks and bye Steffen

Reply via email to