Modify FlushError description to take account of possible missing auto_increment setting
Hi,
received FlushError today after performing: Session.add(obj), Session.commit():
"FlushError: Instance <MyInstance at 0xxxxxx> has a NULL identity key. Check if this flush is occurring at an inappropriate time, such as during a load operation."
Using SQLA 0.6.7 with Declarative ext, my SQLA model had a single PK Column: Integer, primary_key=True, autoincrement=True
As it turned out, I was missing auto_increment setting on my (MySQL) table (created by hand) which prompted this sanity check as there was no last_insert_id()
I suggest adding a more robust description to the error, listing missing auto increment setting as one of the possiblities for this error.
Regards.
Comments (4)
-
repo owner -
repo owner Instance X has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the SQLAlchemy mapped Table and Column object is configured to expect these generated values. Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.
-
repo owner d9a2c64a412feb5341eb1b7f27452af30455b7c9 907a4988408a8cb3748b657a7911426c99689582
thanks for the bug report !
-
repo owner - removed milestone
Removing milestone: 0.6.8 (automated comment)
- Log in to comment
Here is another case...need to add "no autoincrementing primary keys present" or something like that
will consider an 0.6.8 backport once I decide how big a change we're going to do here.