What database?
On Oct 29, 3:05 am, Ruiwen Chua <[email protected]> wrote: > Hi, > > Just wondering if it's possible to have fields that optionally > reference other fields? For example, I have the below table defined: > > # Message model > db.define_table('message', > Field('sender', custom_auth_table, writable=False, required=True, > notnull=True), > Field('recipient', custom_auth_table, writable=False, requires=[], > required=True, ondelete="NO ACTION"), > Field('text', 'string', length=2048, required=True, notnull=True), > Field('created', 'datetime', default=request.now, writable=False, > notnull=True) > ) > > However, a Message, doesn't always have a specific 'recipient', ie. it > could be a broadcast message to all users. > > In this case, I would like to store NULL or 0 as the field value. > > However, when I try to save None | 'NULL' | 0 to the field, I get the > error below: > > IntegrityError: (1452, 'Cannot add or update a child row: a foreign > key constraint fails (`roverus`.`message`, CONSTRAINT `message_ibfk_2` > FOREIGN KEY (`recipient`) REFERENCES `auth_user` (`id`) ON DELETE NO > ACTION)') > > Would anyone have any tips on how I might go about achieving this? > > Cheers > Ruiwen

