Assuming I define my tables using the following:

CREATE TABLE users (
id SERIAL NOT NULL,
username VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
UNIQUE (username)
)
CREATE TABLE posts (
id SERIAL NOT NULL,
title VARCHAR(255) NOT NULL,
body TEXT NOT NULL,
user_id INTEGER,
PRIMARY KEY (id),
FOREIGN KEY(user_id) REFERENCES users (id) ON DELETE CASCADE
)
When I delete a user using DELETE FROM users WHERE id = 1, the user and
all of her posts should be deleted. This isn't the behavior in
SQLAlchemy when I do Session.delete(post), which instead sets the
posts.user_id to NULL, then deletes the user.


There are two problems here. If I have a null constraint on
posts.user_id, the delete violates the null constraint. If I don't have
a null constraint, the post never gets deleted.


Unit tests with failing cases: https://gist.github.com/736945

This appears to be the same problem discussed but not resolved in
https://groups.google.com/d/topic/sqlalchemy/RTDf__0_VYU/discussion



What's the best way to go about configuring SQLAlchemy to behave as
expected?

-- 
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.

Reply via email to