Hi
How do i define a delete-orphan using declarative base?
I am using sqlite and SA0.5.5
I have defined a one to one relation.
class Child(DeclarativeBase):
    __tablename__='children'
    id=Column(String(50),primary_key=True)
    parent_id=Column(String(50),ForeignKey
('parent.id',onupdate="CASCADE",ondelete="CASCADE"))
    name=Column(String(50))

class Parent(DeclarativeBase):
    __tablename__='parent'
    id=Column(String(50),primary_key=True)
    name=Column(String(50))
    children=relation('Child', uselist=False)

when i delete the parent it makes the parent_id None in Child.

I tried giving ondelete=DELETE according to
http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/schema.html#sqlalchemy.schema.ForeignKey
"ondelete – Optional string. If set, emit ON DELETE <value> when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT."
But gave syntax error while trying to create the child table near
DELETE

I tried making parent_id as primarykey for Child.But that gave the
error Constraint tried to blank out the
PrimaryKey for instance....

what am i doing wrong?
thnx in advance.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to