I have a ManyToOne() relationship defined with both required=True, and
ondelete='cascade'. When deleting a record from the parent table,
Elixir is trying to update related records in the child table and set
the parent_id = Null, which is invalid since it is a NOT NULL column.
If I remove the corresponding field in the parent object, I don't have
the problem any more. Any ideas?
My object defs:
class ContentBaseAttributeCategory(Entity):
name = Field(Unicode(255), required=True, unique=True, index=True)
display = Field(Unicode(1000))
inactive = Field(Boolean, required=True, server_default=text("0"))
created = Field(DateTime, required=True,
default=datetime.datetime.now)
last_edited = Field(DateTime, onupdate=datetime.datetime.now)
## if uncommented, SQL errors are generated
#attributes = OneToMany('ContentBaseAttribute')
using_options(tablename="contentbase_attribute_categories")
class ContentBaseAttribute(Entity):
category = ManyToOne('ContentBaseAttributeCategory',
required=True, ondelete='cascade')
name = Field(Unicode(255), required=True)
display = Field(Unicode(1000))
sort_order = Field(Integer, required=True,
server_default=text("0"))
inactive = Field(Boolean, required=True, server_default=text("0"))
created = Field(DateTime, required=True,
default=datetime.datetime.now)
last_edited = Field(DateTime, onupdate=datetime.datetime.now)
items = ManyToMany('ContentBaseItem',
tablename='contentbase_attribute_item_map', ondelete='cascade')
using_options(tablename="contentbase_attributes")
def get_catname(self):
return
self.category.name
catname = property(get_catname)