Discussion:
NOT NULL constraint failed: snippets_snippet.owner_id
Gilgamesh
2018-05-26 07:23:51 UTC
Permalink
I am new to the programming and following the tutorial as it is. But can't
seem to get past the 4th chapter "Authentication and permissions". At the
end of the tutorial I'm trying to create the snippet programmatically but
I'm getting error "NOT NULL constraint failed: snippets_snippet.owner_id" .
Am I missing something ? I Did as the tutorial said.
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Piotr Ogrodowicz
2018-05-26 13:14:24 UTC
Permalink
What you have to do is to set up the owner of this snippet manually.
Post by Gilgamesh
from snippets.models import Snippet
from django.contrib.auth.models import User
snippet_owner = User.objects.all().first()
print(snippet_owner)
snpt = Snippet()
snpt.owner = snippet_owner
snpt.code = "It works"
snpt.save()
Then it's saved. You can find it through API
Post by Gilgamesh
I am new to the programming and following the tutorial as it is. But can't
seem to get past the 4th chapter "Authentication and permissions". At the
end of the tutorial I'm trying to create the snippet programmatically but
I'm getting error "NOT NULL constraint failed: snippets_snippet.owner_id" .
Am I missing something ? I Did as the tutorial said.
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...