3995

Why is Django giving me: 'first_name' is an invalid keyword argument for this function?

I'm trying to create a custom user profile and have modified the example only slightly

from django.conf import settings from django.db import models from django.contrib.auth.models import BaseUserManager, AbstractBaseUser class MyUserManager(BaseUserManager): def create_user(self, email, password=None, first_name=None, last_name=None): if not email: raise ValueError('Users must have an email address') user = self.model( email=MyUserManager.normalize_email(email), first_name=first_name, last_name=last_name, #date_of_birth=date_of_birth, ) user.set_password(password) user.save(using=self._db) return user def create_superuser(self, email, password, first_name=None, last_name=None): user = self.create_user(email, password=password, first_name=first_name, last_name=last_name, #date_of_birth=date_of_birth ) user.is_admin = True user.save(using=self._db) return user class MyUser(AbstractBaseUser): email = models.EmailField( verbose_name='email address', max_length=255, unique=True, db_index=True, ) first_name=models.CharField(max_length = 30), last_name=models.CharField(max_length = 30), #date_of_birth = models.DateField() is_active = models.BooleanField(default=True) is_admin = models.BooleanField(default=False) objects = MyUserManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = [] def get_full_name(self): # The user is identified by their email address return self.email def get_short_name(self): # The user is identified by their email address return self.email def __unicode__(self): return self.email def has_perm(self, perm, obj=None): "Does the user have a specific permission?" # Simplest possible answer: Yes, always return True def has_module_perms(self, app_label): "Does the user have permissions to view the app `app_label`?" # Simplest possible answer: Yes, always return True @property def is_staff(self): "Is the user a member of staff?" # Simplest possible answer: All admins are staff return self.is_admin

When I try to run syncdb I get the following error:

You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Email address: uou@pce.com Password: Password (again): TypeError: 'first_name' is an invalid keyword argument for this function

I have struggled to debug this because of the limited nature of the error message. I feel I'm making a simple mistake what am I doing wrong?

Answer1:

You are trying to set None (Null) value into first_name and it seems that this property don't allow it.

Try this changes:

class MyUserManager(BaseUserManager): def create_user(self, email, password=None, first_name='', last_name=''):

In model:

first_name=models.CharField(max_length = 30, blank = True)

Recommend

  • can not login with Extended AbstractBaseUser model
  • Modify response from Django REST API using CustomUserModel extending default User Model and API clas
  • Update the instance after save, using signals by conditionally refference back to the instance in so
  • How to add fields in extended UserAdmin
  • FOREIGN KEY constraint failed in django admin panel when creating/editing/deleting a user. (Using cu
  • Why echoing a local variable inside the same function is not working? [duplicate]
  • Isotope Filtering - Issues when reset to start position
  • Inno Setup: How to put the installer itself in the installed program
  • Delphi - TSQLQuery leaving a proccess on MySQL even after been freed
  • How to FindResource (pinvoke) a string resource in C#?
  • How do I extend UserCreationForm to include email field
  • Timer is not working in separate class in C#
  • Bullet-Proof ACL using AngularJS
  • Cannot send user message with Spring Websocket
  • Email notification to a particular address if a specific product is purchased in Woocommerce
  • Extending the Django 1.11 User Model
  • C++ Partial template specialization - design simplification
  • How to use an array of arrays with array_map(…) in PHP?
  • Different response to non-authenticated users and AJAX calls
  • jQuery show() function is not executed in Safari if submit handler returns true
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • output of program is not same as passed argument
  • Incrementing object id automatically JS constructor (static method and variable)
  • Eraser for UIBezierPath
  • How to limit post in wp_query
  • Upload files with Ajax and Jquery
  • Build own AppleScript numerical error handling
  • AngularJs get employee from factory
  • Java static initializers and reflection
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Change div Background jquery
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Is there any way to bind data to data.frame by some index?
  • Django query for large number of relationships
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?