Seems I got the append wrong, the below works fine, thanks again for your help.
due_con.due_user = c.user contact.due_dates.append(due_con) On Tue, Jul 10, 2012 at 8:46 AM, Jules Stevenson <droolz...@googlemail.com>wrote: > Hi Michael, > > Yes, I am doing this: > > due_con = model.ArkContactDueDate() > due_con.modded = > arkUtils.process_date(field_dataList['duecontact']) > due_con.contact = contact > > #todo: cannot append since it gives a duff default error message. > #have triple checked against docs and DB looks sound, so not sure.. > c.user.due_contacts.append(due_con) > > ...but still get the error - is there anything else I can look into? Thank > you for getting back to me, the level of support you give is outstanding. > > Jules > > On Mon, Jul 9, 2012 at 11:40 PM, Michael Bayer > <mike...@zzzcomputing.com>wrote: > >> >> On Jul 9, 2012, at 6:08 PM, Jules Stevenson wrote: >> >> Hi All, >> >> I'm trying to put together an Association Object mapping within a pylons >> app, but am getting the following error: >> >> OperationalError: (OperationalError) (1364, "Field 'user_id' doesn't have >> a default value") 'INSERT INTO contact_duedate_user_association >> (contact_id, modded) VALUES (%s, %s)' (209L, datetime.date(2012, 7, 18)) >> >> As far as I can tell I've followed the recomendations in the association >> object help and am somehwta stumped as to what is causing the error. The >> classes are non-declarative, and are as follows (and if the formatting >> holds up the relevant bits should be in bold). Any help enormously >> appreciated. >> >> >> mapping looks fine, you'd need to ensure every ArkContactDueDate you add >> to the Session is associated with a User also in that session. >> single_parent=True should not be needed here. >> >> >> >> >> >> contacts_table = sa.Table('contacts', meta.metadata, >> sa.Column('id', sa.types.Integer, primary_key=True), >> sa.Column('project_id', sa.types.Integer, sa.ForeignKey('projects.id >> ')), >> sa.Column('client_id', sa.types.Integer, sa.ForeignKey('clients.id >> ')), >> sa.Column('firstname',sa.types.String(length=255)), >> sa.Column('lastname', sa.types.String(length=255)), >> sa.Column('email1', sa.types.String(length=255)), >> sa.Column('email2', sa.types.String(length=255)), >> sa.Column('workphone', sa.types.String(length=255)), >> sa.Column('mobile', sa.types.String(length=255)), >> sa.Column('company', sa.types.String(length=255)), >> sa.Column('category', sa.types.String(length=255)), >> sa.Column('job_role', sa.types.String(length=255)), >> sa.Column('mailer', sa.types.Boolean), >> sa.Column('type', sa.types.Integer), # 0: contact, 1: press >> sa.Column('modified', sa.types.DateTime), >> ) >> >> class ArkContact(object): >> def __init__(self): >> self.category = 0 >> self.type = 0 >> self.modified = datetime.datetime.now() >> >> *#due_contact_association >> contact_due_contact = sa.Table('contact_duedate_user_association', >> meta.metadata, >> sa.Column('contact_id', sa.types.Integer, sa.ForeignKey('contacts.id'), >> primary_key = True), >> sa.Column('user_id', sa.types.Integer, sa.ForeignKey('users.id'), >> primary_key = True), >> sa.Column('modded', sa.types.Date) >> ) >> >> class ArkContactDueDate(object): >> def __init__(self): >> pass* >> >> >> *# ArkContactDueDate >> orm.mapper(ArkContactDueDate, contact_due_contact, properties={ >> 'contact': orm.relation(ArkContact, backref = 'due_dates') >> })* >> >> # ArkUser - users module >> orm.mapper(ArkUser, users_table, properties={ >> 'notes': orm.relation(ArkNote, >> secondary=user_notes_table, >> single_parent=True, >> backref='user', >> order_by=notes_table.c.date, >> cascade="all, delete, delete-orphan"), >> 'software': orm.relation(ArkSoftware, >> secondary=user_software_table, >> backref='users'), >> 'ratings': orm.relation(ArkUserSoftwareRating, >> cascade="all, delete", >> backref='user'), >> 'job': orm.relation(ArkJob, >> backref='user'), >> * 'due_contacts': orm.relation(ArkContactDueDate, >> backref = 'due_user', >> single_parent=True)* >> }) >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to sqlalchemy@googlegroups.com. >> To unsubscribe from this group, send email to >> sqlalchemy+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/sqlalchemy?hl=en. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to sqlalchemy@googlegroups.com. >> To unsubscribe from this group, send email to >> sqlalchemy+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/sqlalchemy?hl=en. >> > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.