What you have to do is to set up the owner of this snippet manually. 
Assuming, you have superuser created:

>>> 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

W dniu sobota, 26 maja 2018 09:23:51 UTC+2 użytkownik Gilgamesh napisał:
>
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to