this can happen if you are using the wrong datatype for your primary key.  like 
it's a string in the database and you are referring to it as an Integer, that 
kind of thing.

no way to provide more detail without seeing a short version of the mapping 
that produces this error and CREATE TABLE statement used in the database.

On Wed, Apr 26, 2023, at 6:23 AM, Mirel Glejser wrote:
> I am completely stumped after working on this issue for 2 days.
> 
> I am simply querying a user, updating the name, and sending it back to the 
> database.
> 
> user = session.query(User).get(1)
> user.first_name # John 
> user.first_name = 'Sally' 
> session.commit()
> 
> # > sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'user' 
> expected to update 1 row(s); # -1 were matched.
> 
> What is causing this error?
> 
> 
> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/
>  
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/0eed0704-5c66-48f4-a41f-73512b18f858n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/0eed0704-5c66-48f4-a41f-73512b18f858n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/176253d9-5dcf-4484-934d-b07741113003%40app.fastmail.com.

Reply via email to