Can't create super user with custom user model in Django 1.5
There are three ways for you in this case
1) Make relation to company Not required company = models.ForeignKey('Company', null=True)
2) Add default company and provide it as default value to foreign key field company = models.ForeignKey('Company', default=1)
#where 1 is id of created company
3) Leave model code as is. Add fake company for superuser named for example 'Superusercompany' set it in create_superuser method.
UPD: according to your comment way #3 would be the best solution not to break your business logic.
Thanks to your feedback here is the solution I made: A custom MyUserManager where I created a default company
def create_superuser(self, email, password, company=None):
"""
Creates and saves a superuser with the given email and password.
"""
if not company:
company = Company(
name="...",
address="...",
code="...",
city="..."
)
company.save()
user = self.create_user(
email,
password=password,
company=company
)
user.is_admin = True
user.save(using=self._db)
return user