help on creating user profile using drf

24 views
Skip to first unread message

ola neat

unread,
Jul 26, 2020, 1:01:28 PM7/26/20
to django...@googlegroups.com
good day, i'm working on a project that allow user create their profile after they have signup, thereby having 2 seperate model, User and Profile but i'm getting a not null constraint error, below is they screenshot of my code and err msg

Screenshot from 2020-07-26 17-59-12.png
Screenshot from 2020-07-26 17-58-50.png
Screenshot from 2020-07-26 17-58-18.png
Screenshot from 2020-07-26 17-57-57.png
Screenshot from 2020-07-26 17-57-13.png

Fernando Hernandez

unread,
Jul 26, 2020, 9:24:52 PM7/26/20
to django...@googlegroups.com
I think the issue is here instance.profile will be None first time the CustomUser is created, you need to assign the created Profile to the instance and then save the user 
image.png
try this 
if created: 
    instance.profile = Profile.objects.create(user=instance)
    instance.save()


   

On Sun, Jul 26, 2020 at 2:00 PM ola neat <tosina...@gmail.com> wrote:
good day, i'm working on a project that allow user create their profile after they have signup, thereby having 2 seperate model, User and Profile but i'm getting a not null constraint error, below is they screenshot of my code and err msg

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHLKn73K5hEjn%3DzeoQQtaZBOTj4J6f4LH45V1xOKSE6E%3DoOeFQ%40mail.gmail.com.

ola neat

unread,
Jul 28, 2020, 4:14:05 PM7/28/20
to django...@googlegroups.com
sorry this didnt work, when i try this

if created: 
    instance.profile = Profile.objects.create(user=instance)
    instance.save()
i couldnt even register any user

Reply all
Reply to author
Forward
0 new messages