Composite primary key with nullable columns

202 views
Skip to first unread message

Paul Johnston

unread,
Jan 5, 2016, 12:11:53 PM1/5/16
to sqlalchemy
Hi,

I have a situation where I'm trying to us a composite primary key, where one of the columns can be null.

However, when I try to update an object I get the following error:
sqlalchemy.orm.exc.FlushError: Can't update table test using NULL for primary key value on column test.id2

Sample code here: http://dpaste.com/3Q8T09T

Is this something SQLAlchemy can do? From some quick tests, it seems SQLite can do it, not sure about other databases.

Paul

Matt Zagrabelny

unread,
Jan 5, 2016, 12:18:59 PM1/5/16
to sqlal...@googlegroups.com
NULL columns can't be primary keys in Pg - not sure if it is an ANSI
SQL standard.

-m
Reply all
Reply to author
Forward
0 new messages