Forums

POST nested objects works perfectly locally, but not when deployed to a server.

Django rest app works perfectly locally, but not when deployed to a server. Getting an error while trying to post nested objects.

enter image description here


2017-08-18 11:19:39,907: Internal Server Error: /meals/#012Traceback (most recent call last):#012  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 149, in get_response#012    response = self.process_exception_by_middleware(e, request)#012  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 147, in get_response#012    response = wrapped_callback(request, *callback_args, **callback_kwargs)#012  File "/usr/local/lib/python3.5/dist-packages/django/views/decorators/csrf.py", line 58, in wrapped_view#012    return view_func(*args, **kwargs)#012  File "/home/doskonale/.local/lib/python3.5/site-packages/rest_framework/viewsets.py", line 83, in view#012    return self.dispatch(request, *args, **kwargs)#012  File "/home/doskonale/.local/lib/python3.5/site-packages/rest_framework/views.py", line 477, in dispatch#012    response = self.handle_exception(exc)#012  File "/home/doskonale/.local/lib/python3.5/site-packages/rest_framework/views.py", line 437, in handle_exception#012    self.raise_uncaught_exception(exc)#012  File "/home/doskonale/.local/lib/python3.5/site-packages/rest_framework/views.py", line 474, in dispatch#012    response = handler(request, *args, **kwargs)#012  File "/home/doskonale/.local/lib/python3.5/site-packages/rest_framework/mixins.py", line 21, in create#012    self.perform_create(serializer)#012  File "/home/doskonale/.local/lib/python3.5/site-packages/rest_framework/mixins.py", line 26, in perform_create#012    serializer.save()#012  File "/home/doskonale/.local/lib/python3.5/site-packages/rest_framework/serializers.py", line 214, in save#012    self.instance = self.create(validated_data)#012  File "/home/doskonale/.local/lib/python3.5/site-packages/rest_framework/serializers.py", line 888, in create#012    raise_errors_on_nested_writes('create', self, validated_data)#012  File "/home/doskonale/.local/lib/python3.5/site-packages/rest_framework/serializers.py", line 780, in raise_errors_on_nested_writes#012    class_name=serializer.__class__.__name__#012AssertionError: The `.create()` method does not support writable nested fields by default.#012Write an explicit `.create()` method for serializer `restapp.serializers.MealNestedSerializer`, or set `read_only=True` on nested serializer fields.

If you're getting a 500 internal server error, the first place to look is at the error log, which is linked from the "Web" tab. The most recent error stacktrace will be at the end of the file. Check that out and see if you can find out the cause.

I have updated diango to the latest version, everything seems to be working fine.

:)