Django Foreign Key to_field -


i have 2 models customuser , magazine random/unique slug fields. want create third model (article) foreign keys slug field:

class customuser(abstractbaseuser):     slug = randomslugfield(length=6, unique=true)     ...   class magazine(models.model):     slug = randomslugfield(length=6, unique=true)     name = models.charfield()   class article(models.model):     magazine = models.foreignkey(magazine, to_field='slug')     author = models.foreignkey(settings.auth_user_model, to_field='slug') 

but when migrate database create article model, following error:

django.core.exceptions.fielddoesnotexist: customuser has no field named 'slug' 

but customuser has field named 'slug'. , magazine model don't error. has idea going wrong?

i use package slug field: https://github.com/mkrjhnsn/django-randomslugfield

edit: here full customuser model:

class customuser(abstractbaseuser, permissionsmixin):      slug = randomslugfield(length=6, exclude_upper=true)      username = models.charfield(         _('username'), max_length=30,         help_text=_('required. 30 characters or fewer.'                 'letters, digits , '                 '@/./+/-/_ only.'),         validators=[             validators.regexvalidator(r'^[\w.@+-]+$',                                   _('enter valid username.'), 'invalid')         ])     first_name = models.charfield(_('first name'), max_length=30, blank=true)     last_name = models.charfield(_('last name'), max_length=30, blank=true)      # email our unique field authentication     email = models.emailfield(_('email address'), unique=true)      is_staff = models.booleanfield(         _('staff status'), default=false,         help_text=_('designates whether user can log '                     'into admin site.')         )     is_active = models.booleanfield(         _('active'),         default=true,         help_text=_('designates whether user should treated '                     'active. unselect instead of deleting accounts.')         )     date_joined = models.datetimefield(_('date joined'), default=timezone.now)      objects = usermanager()      profile = models.onetoonefield('userprofile', blank=true, null=true,                                related_name='user_profile')      image = models.imagefield(default='images/noimage.jpg',                           upload_to=settings.profile_image_path,                           max_length=255)      username_field = 'email'     required_fields = ['username'] 


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -