0

I'm still pretty new to Django, and have been having a problem defining my own user model that inherits from the Abstract User in Django. However, I have users already in the databse (with only usernames and passwords) and when I try to migrate the changes, I get the error that the email field is required and doesn't have a default value.

What confuses me is that I looked it up in the docs, and at https://docs.djangoproject.com/en/1.7/ref/contrib/auth/ the email field is clearly listed as optional. Furthermore, when I try to override the email field I get an error that my field clashes with the existing one.

Why is it giving me this error, and how do I fix it?

models.py

from django.db import models from django.contrib.auth.models import AbstractUser class UserProfile(AbstractUser): additionalFields = models.IntegerField(default=0) def __unicode__(self): return self.username 

1 Answer 1

1

EmailField is a text field in the database, and 'empty' text fields are saved as an empty string (''). They are not empty (NULL) on a database level, and the column is defined as NOT NULL. What you need to do is set a default of '', then the migration will work.

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

1 Comment

Thanks, so the problem was that NULL is different from an empty field

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.