1👍
Answered my own question. When a User is created & saved, the UserProfile is created/saved as well – this we know. What I did not know is that Dates, Booleans and integers cannot be null as stated here. So, the solution is to change this line of the UserProfile class:
age = models.DateField()
to
age = models.DateField(null=True)
This allows the UserProfile to be saved to the DB without being populated, and for me to retrieve it with get_profile() and populate it later.
0👍
Did you check if age is not empty?
Why not to create user via userprofile? What i mean is:
profile.first_name = 'abc'
profile.last_name = 'abc'
profile.age = Date(2000, 1, 1)
profile.save()
- [Answer]-AttributeError when establishing a foreign key using the to_field option
- [Answer]-Database Error on Dotcloud, Postgres Django
- [Answer]-Module has no attribute 'index'?
- [Answer]-Effect of clicking back on a browser on the context variables
- [Answer]-Django 1.5. Users attributes in comments framework
0👍
I think you have to add AUTH_PROFILE_MODULE
to you settings.py so as to automatically create a user profile after a new user is saved. Did you check this documentation?
- [Answer]-Django: updating src on iframe without refreshing
- [Answer]-Is it possible to change the behavior in view of existing apps after new app is installed with touching the existing apps?
- [Answer]-Automatic HTTPRedirect in Django view if user is authenticated?
- [Answer]-Sending e-mails in django works locally but not online
Source:stackexchange.com