title: IntegrityError at /users/signup NOT NULL constraint failed: users_user.username
body: <h1>What I was doing</h1>
  <p>I was making the signup form with using ModelForm in forms.py and FormView in views.py. I am making users to use their email as their username when they are logging in so that they can easily set new passwords if they lost.</p>
  <h1>Error Image</h1>
  <p>It just threw <code>IntegrityError</code> in my console.</p>
  <p><a href="https://i.stack.imgur.com/Btyat.png" rel="nofollow noreferrer">IntegrityError at / NOT NULL contraint failed</a></p>
  <h1>What I have tried to solve issue</h1>
  <ol>
  <li>I deleted all the migration files and db file so that there won't be any duplicated users in my database. And then I created new superuser and then created new user.</li>
  <li>I got rid of <code>email</code> field in <code>fields</code> in <code>Meta</code> class and then created cleaning method of email (<code>def clean_email(self):</code>). However this solution didn't work obviously because it will delete the email field in my signup form.</li>
  </ol>
  <h1>Source code</h1>
  <p>Below are my all source codes that might be related to this topic.</p>
  <ol>
  <li>templates/users/signup.html</li>
  </ol>
  <pre><code>{% block content %}
      &lt;section id=&quot;signup&quot;&gt;
          &lt;form method=&quot;POST&quot;, action=&quot;{% url 'users:signup' %}&quot;&gt;
              {% csrf_token %}
              {{ form.as_p }}
              &lt;button type=&quot;submit&quot;&gt;Signup&lt;/button&gt;
          &lt;/form&gt;
      &lt;/section&gt;
  {% endblock content %}
  </code></pre>
  <ol start="2">
  <li>users/forms.py</li>
  </ol>
  <pre class="lang-py prettyprint-override"><code>class SignupForm(forms.ModelForm):
      class Meta:
          model = models.User
          fields = ['first_name', 'last_name', 'email']
  
      password = forms.CharField(widget=forms.PasswordInput)
      confirm_password = forms.CharField(widget=forms.PasswordInput, label='Confirm Password')
  
      # Validating password 
      def clean_confirm_password(self):
          password = self.cleaned_data.get('password')
          confirm_password = self.cleaned_data.get('confirm_password')
          if password != confirm_password:
              raise forms.ValidationError('Password should be matched!')
          else: 
              return password 
  
      def save(self, *args, **kwargs):
          user = super().save(commit=False)
          username = self.cleaned_data.get('username')
          password = self.cleaned_data.get('password')
          user.username = username
          user.set_password = password 
          user.save()
  </code></pre>
  <ol start="3">
  <li>users/view.py</li>
  </ol>
  <pre class="lang-py prettyprint-override"><code>class SingupView(FormView):
      template_name = 'users/signup.html'
      form_class = forms.SignupForm
      success_url = reverse_lazy('common:home')
  
      def form_valid(self, form):
          form.save()
          email = form.cleaned_data.get('email')
          password = form.cleaned_data.get('password')
          user = authenticate(self.request, username=email, password=password)
          if user is not None:
              login(self.request, user)
          return super().form_valid(form) 
  </code></pre>
  <p>My github repo is <a href="https://github.com/donghhan/knowner-website.git" rel="nofollow noreferrer">https://github.com/donghhan/knowner-website.git</a></p>
  <p>Please give me a help!</p>