Michael Bayer wrote:
On Jul 18, 2006, at 5:54 PM, Randall Smith wrote:
SQLError: (IntegrityError) null value in column "project_id" violates
not-null constraint
'UPDATE planreview.documents SET project_id=%(project_id)s WHERE
documents.id = %(documents_id)s' {'project_id': None,
'documents_id': 13}
Shouldn't this be a delete statement?
yup. you need to post a fully working test case (strongly preferred:
sqlite, single .py file) since i cannot reproduce this error in
similar setups.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Did it. Attached is an example of the problem.
Randall
"""Delete fails after access to a lazy attribute.
"""
from sqlalchemy import *
metadata = DynamicMetaData(name="test")
t1 = Table('t1', metadata,
Column('id', Integer, primary_key=True),
Column('name', String)
)
t2 = Table('t2', metadata,
Column('id', Integer, primary_key=True),
Column('t1_id', Integer, ForeignKey(t1.c.id)),
Column('name', String)
)
class T1(object):
pass
class T2(object):
pass
# If I define the relationship off of T1, no problem. It's when I define the
# relationship of of T2 that problems occur.
mapper(T1, t1,
## properties={'t2s':relation(T2, backref='t1', private=True)}
)
mapper(T2, t2,
properties={'t1':relation(T1, backref='t2s', private=True)}
)
engine = create_engine("sqlite:///:memory:")
engine.echo = True
metadata.connect(engine)
metadata.create_all()
# Populate tables.
session = create_session(bind_to=engine)
for i in range(10):
t1obj = T1()
t1obj.name = 'test'
session.save(t1obj)
for i in range(5):
t2obj = T2()
t2obj.name = 'test'
t1obj.t2s.append(t2obj)
session.flush()
session.close()
# Delete
session = create_session(bind_to=engine)
t2obj = session.query(T2).select()[0]
print t2obj.t1 # This is what causes the problems.
session.delete(t2obj)
session.flush()
session.close()
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users