Skip to content
Advertisement

Saving custom user model with django-allauth

I have django custom user model MyUser with one extra field:

JavaScript

I also have according to these instructions custom all-auth Signup form class:

JavaScript

After submitting SignupForm (field for property MyUser.age is rendered corectly), I get this error:

IntegrityError at /accounts/signup/
(1048, “Column ‘age’ cannot be null”)

What is the proper way to store Custom user model?

django-allauth: 0.12.0; django: 1.5.1; Python 2.7.2

Advertisement

Answer

Though it is a bit late but in case it helps someone.

You need to create your own Custom AccountAdapter by subclassing DefaultAccountAdapter and setting the

JavaScript

and you also need to define the following in settings:

JavaScript

This is also useful, if you have a custom SignupForm to create other models during user registration and you need to make an atomic transaction that would prevent any data from saving to the database unless all of them succeed.

The DefaultAdapter for django-allauth saves the user, so if you have an error in the save method of your custom SignupForm the user would still be persisted to the database.

So for anyone facing this issue, your CustomAdpater would look like this

class UserAccountAdapter(DefaultAccountAdapter):

JavaScript

Then you can decorate your custom SignupForm’s with @transaction.atomic

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement