0

I'm using fastAPI for backend and SQL Server for the database. Every time I try to PATCH, I get this error:

(pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot update identity column 'id'.

Is there any ways for me to do some PATCH or PUT data in SQL Server from fastAPI? Thank you!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • fastAPI uses Pydantic for its data models. Have you tried setting `orm_mode = True` in your model? Ref: [ORM Mode (aka Arbitrary Class Instances)](https://pydantic-docs.helpmanual.io/usage/models/#orm-mode-aka-arbitrary-class-instances) – AlwaysLearning Oct 25 '21 at 03:16
  • 1
    Does this answer your question? [How to update Identity Column in SQL Server?](https://stackoverflow.com/questions/19155775/how-to-update-identity-column-in-sql-server) – MatsLindh Oct 25 '21 at 06:59
  • In general, you can't update the identity column (in this case `id`), so you need to modify your query to not attempt to change the value of the `id` column - just use it in the `WHERE` statement; this isn't in particular related to fastapi or pydantic, it's about how you're issuing your query to SQL Server. – MatsLindh Oct 25 '21 at 07:00

0 Answers0