[Django] save() prohibited to prevent data loss due to unsaved related object

2019.10.14 11:09Trouble Shooting

 

Internal Server Error: /customer/1
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/views/generic/base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/views/generic/base.py", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/views/generic/edit.py", line 194, in post
    return super().post(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/views/generic/edit.py", line 142, in post
    return self.form_valid(form)
  File "/car/crms/crm/customer/detail.py", line 283, in form_valid
    config = self.alarm(r, counsel)
  File "/car/crms/crm/customer/detail.py", line 251, in release_alarm
    cc.save()
  File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 685, in save
    "unsaved related object '%s'." % field.name
ValueError: save() prohibited to prevent data loss due to unsaved related object 'alarm'.

django value error

django 1.8.4에서 적용된 오류인데, 1.8.5에서는 넣다뺏다 지롤을 하네요

 

해당 에러는 관계형 DB에서 해당 테이블내에 초기화를 안해줘서 그렇답니다.

 

 

참고자료

https://stackoverflow.com/questions/33838433/save-prohibited-to-prevent-data-loss-due-to-unsaved-related-object

 

save() prohibited to prevent data loss due to unsaved related object

I need to pass a primary key from a newly created ModelForm to another form field in the same view but I get an error. Any suggestions to make this work? It looks like in the past, this would be the

stackoverflow.com

그냥 default값을 create당시에 할당 해 주시면됩니다.