Thursday, 6 October 2022

python django db exception and handling

https://stackoverflow.com/questions/47615512/django-matching-query-does-not-exist

Django model does not exist exception

 airlines = RecordSet.objects.get(name="airline")

You are retrieving a single object with get() and since it does not exist, it returns DoesNotExist exception. This is also clearly mentioned in the Django documentation in the subchapter Retrieving a single object with get()


//

can get away with using get_or_create


but do handle exception: 


https://stackoverflow.com/questions/60222340/catching-errors-when-querying-in-django-of-fields-that-do-not-exist-in-the-datab


       tbl_dict  = Bin.objects.values('bin_height_mm_desc','received_at_ymd','received_at_hm')
        except FieldError as e:
             tbl_dict = e   

No comments:

Post a Comment