Re: [sqlalchemy] Problem deleting an item

2010-11-22 Thread Michael Bayer

On Nov 22, 2010, at 4:32 PM, Alvaro Reinoso wrote:

> Hello all,
> 
> I have these classes:
> 
> class Screen(rdb.Model):
>   """Represents the screen"""
>   rdb.metadata(metadata)
>   rdb.tablename("screens")
> 
>   id = Column("id", Integer, primary_key=True)
>   title = Column("title", String(100))
>..
> 
>   crm = relationship("CRM", uselist=False, backref="screens")
> 
> class CRM(rdb.Model):
>   """Represents the CRM Tab"""
>   rdb.metadata(metadata)
>   rdb.tablename("crms")
> 
>   id = Column("id", Integer, ForeignKey("screens.id"),
> primary_key=True)
>title = Column("title", String(50))
>   contactInformation = relationship("CRMContactInformation",
> uselist=False, backref="crms")
>   endpointConfiguration = relationship("CRMEndpointConfiguration",
> uselist=False, backref="crms")
>   location = relationship("CRMLocation", uselist=False, backref="crms")
>   slaEvent = relationship("CRMSLAEvent", uselist=False, backref="crms")
>   notes = relationship("CRMNote", uselist=True, backref="crms")
>   log = relationship("CRMLog", uselist=True, backref="crms")
> 
> I get this error when trying to delele a screen object:
> 
> session.delete(screen)
> AssertionError: Dependency rule tried to blank-out primary key column
> 'crms.id' on instance ''

Its illegal for a primary key attribute to be NULL, so when deleting a Screen 
you need to delete the CRM as well.  Configure 'cascade="all, delete-orphan"' 
on your crm relationship.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.



[sqlalchemy] Problem deleting an item

2010-11-22 Thread Alvaro Reinoso
Hello all,

I have these classes:

class Screen(rdb.Model):
"""Represents the screen"""
rdb.metadata(metadata)
rdb.tablename("screens")

id = Column("id", Integer, primary_key=True)
title = Column("title", String(100))
..

crm = relationship("CRM", uselist=False, backref="screens")

class CRM(rdb.Model):
"""Represents the CRM Tab"""
rdb.metadata(metadata)
rdb.tablename("crms")

id = Column("id", Integer, ForeignKey("screens.id"),
primary_key=True)
title = Column("title", String(50))
contactInformation = relationship("CRMContactInformation",
uselist=False, backref="crms")
endpointConfiguration = relationship("CRMEndpointConfiguration",
uselist=False, backref="crms")
location = relationship("CRMLocation", uselist=False, backref="crms")
slaEvent = relationship("CRMSLAEvent", uselist=False, backref="crms")
notes = relationship("CRMNote", uselist=True, backref="crms")
log = relationship("CRMLog", uselist=True, backref="crms")

I get this error when trying to delele a screen object:

session.delete(screen)
AssertionError: Dependency rule tried to blank-out primary key column
'crms.id' on instance ''

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.