2

I'm trying to add a custom field to already existed django's User model.

I want all fields of default User model(including password hashing functionality) + a custom field has_car, so I did ...

class MyUser(AbstractBaseUser): has_car = models.BooleanField(default=False) 

and register in admin panel admin.site.register(MyUser)

when I try to add open this model in admin panel I get this error.

OperationalError at /admin/myapp/myuser/ (1054, "Unknown column 'myapp_myuser.id' in 'field list'") 

I'm not sure if its a mysqldb error or what?

I know I can use OneToOne or ForeignKey field but I simply want to extend User model. again, It django==1.7b4 + Mysql

1 Answer 1

5

If you're just looking to add custom fields to the standard User model, your user model should inherit from AbstractUser instead of from AbstractBaseUser.

Don't forget to set:

AUTH_USER_MODEL = 'myapp.MyUser' 

https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-django-s-default-user

Sign up to request clarification or add additional context in comments.

6 Comments

I've tried that as well. I'm getting this error. auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'myuser.groups'.
@user3745956 are you using proper migrations? If not, drop your database and start fresh.
where do I add AUTH_USER_MODEL = 'myapp.MyUser' this line ?
@user3745956 in your Django configuration settings.
great! Its working! but I have one query. why password is visible to me unlike in default user model password automatically be hashed, even when I type password, using admin interface, we cannot see password instead django show us DOT(as standard password notation) and ask again for confirmation. but in my customuser model password is visible, even after saving the object. how can I get rid of this?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.