0

I would like a bigger auth_user table, including 2-3 extra fields.

The thing is that the code below is creating a new one, exactly the same as the auth_user one with the extra fields but it is not replacing it.

settings.py

AUTH_PROFILE_MODULE = "myaccount.MyUser"

models.py

from django.contrib.auth.models import AbstractUser

    class MyUser(AbstractUser):
    gender = models.DateField()
    location = models.CharField(max_length=30)
    birthday = models.CharField(max_length=30)

Instead of creating a new table called myaccount_MyUser. How can I replace the current auth_user table instead of creating a new table?

3 Answers3

1

I believe that this one can help you :

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

pascalhein
  • 5,700
  • 4
  • 31
  • 44
drabo2005
  • 1,076
  • 1
  • 10
  • 16
  • It is great that you are trying to help the asker out. However, leaving an answer with only a link can be harmful in some cases. While your answer is good now, if the link were ever to die, your answer would lose it's value. So it will be helpful if you summarize the content from the article in your answer. See [this](http://goo.gl/wQTjc) question for clarification. – pascalhein Jul 14 '13 at 13:19
0

One hackish way that I didn't try and don't recommend would be to specify the table name in the model with:

class MyUser(AbstractUser):
    class Meta:
        db_table = auth_user

What I recommend is going along with the new table and migrating the data from the old one using south datamigration. Here is a detailed answer on how to do that:

Migrating existing auth.User data to new Django 1.5 custom user model?

Community
  • 1
  • 1
Viorel
  • 81
  • 4
-1

I think that you have to

import first django.contrib.auth.models 
import AbstractUser 

in your models.py before to get a way to extend with AbstractUser. it should work with that

zurfyx
  • 31,043
  • 20
  • 111
  • 145
drabo2005
  • 1,076
  • 1
  • 10
  • 16
  • I've got it already imported even though I have not written it here. Otherwise it'd have shown me an error. – zurfyx Jul 14 '13 at 12:05
  • ok , try to import also AbstractBaseUser, PermissionsMixin because AbstractUser extend both of this. so you can figure out what happen exactly. – drabo2005 Jul 14 '13 at 12:13
  • Imported both, same result. – zurfyx Jul 14 '13 at 12:15
  • check your settings file about MIDDLEWARE_CLASSES = ( 'django.contrib.auth.middleware.AuthenticationMiddleware',) INSTALLED_APPS = ( 'django.contrib.auth',) – drabo2005 Jul 14 '13 at 12:21
  • ok, let me try something and get back to you if i find solution. – drabo2005 Jul 14 '13 at 12:28