0

I'm trying to update a column value through django model, backed legacy db is postgressql, the column in db is defined as: "numbers integer[] NOT NULL" in my django application's models.py i have the column as : "numbers = ArrayField(models.IntegerField())" in the code i'm trying to update as below:

user = class_name.objects.using('default').get(id=14)
user.numbers = number # here value number is a list
user.save()

this part of code is inside try and exception block i'm not seeing any errors but the save() part is not executing i.e code stops there not going to next lines

view function:

def test(number,value):
try:

user = classname.objects.using('default').get(id=value)
user.numbers = number
user.save()
return Response ({"status": "Success","statusCode": "200",
                                "statusMessage" : "role%s added to user account %s successfully." %((role),(value))},status=status.HTTP_200_OK)
except Exception as e:
logger.error("An error occurred while updating the roles, Error :%s,Reason:%s",str(e),e_msg,extra={'jobid':job_id})
                return Response({"status": "Failure", "statusCode" : "500", "statusMessage": str(e)},                          status=status.HTTP_500_INTERNAL_SERVER_ERROR)

3
  • Can you share the full view which updates the data? Commented Nov 3, 2022 at 9:22
  • view is added to question now @Sunderam Dubey Commented Nov 3, 2022 at 9:57
  • Where is your numbers list in the view, check it's print(type(numbers)) and see whether it is a list of numbers or not. Commented Nov 3, 2022 at 15:08

1 Answer 1

0

AS numbers is a integer field you can only be able to save number(integer) in it. Not a list.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.