how can solve this: null value in column "course_id" of relation "exercise" violates not-null constraint #7978
Unanswered
xiayulu
asked this question in
Question & Answer
Replies: 1 comment
-
I solve this by rewrite: class ExerciseSerializer(serializers.ModelSerializer):
course_id = serializers.PrimaryKeyRelatedField()
class Meta:
model = Exercise
fields = ['id','url', 'title', 'course_id'] to class ExerciseSerializer(serializers.ModelSerializer):
course = serializers.PrimaryKeyRelatedField(
queryset=Course.objects.all()
)
class Meta:
model = Exercise
fields = ['id','url', 'title', 'course'] which means writeable relation must provie a queryset. Now I can code happily again. I hope this will help you. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
My files:
models.py
serializers.py
view.py
urls.py
problem:
When I post data:
using postman, I get this error:
image Here
Can any body help me?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions