title: NOT NULL constraint failed: music_song.album_id
body: <p>I am using django 1.11.6 and python 3.6.2</p>
  
  <p>I'm new to django and there is no one to help me where i live so you guys are all my hope</p>
  
  <p>in my django application in the add song section i faced an error </p>
  
  <p>error message = </p>
  
  <blockquote>
    <p>IntegrityError at /music/album/5/AddSong/ NOT NULL constraint failed:
    music_song.album_id</p>
  </blockquote>
  
  <p>here is my views file:</p>
  
  <pre><code>from django.views import generic
  from django.views.generic import View
  from .forms import UserForm
  from django.views.generic.edit import CreateView,UpdateView,DeleteView
  from django.shortcuts import render,redirect
  from django.contrib.auth import authenticate, login
  
  from .models import Album, Song
  from django.core.urlresolvers import reverse_lazy
  
  
  class IndexView(generic.ListView):
      template_name = 'music/index.html'
      context_object_name = 'all_albums'
  
      def get_queryset(self):
          return Album.objects.all()
  
  
  class DetailView(generic.DetailView):
      model = Album
      template_name = 'music/detail.html'
      context_object_name = 'album'
  
  
  class AlbumCreate(CreateView):
      model = Album
      fields = ['artist', 'album_title', 'genre', 'album_logo']
  
  
  class SongCreate(CreateView):
      model = Song
      fields = ['song_title', 'file_type']
  
  
  
  class AlbumUpdate(UpdateView):
      model = Album
      fields = ['artist', 'album_title', 'genre', 'album_logo']
  
  
  class AlbumDelete(DeleteView):
      model = Album
      success_url = reverse_lazy('music:index')
  
  
  class UserFormView(View):
      form_class = UserForm
      template_name = 'music/registration_form.html'
  
  
      #display a blank form
      def get(self,request):
  
          form = self.form_class(None)
          return render(request,self.template_name, {"form": form})
  
  
      #procces form data
      def post(self,request):
          form = self.form_class(request.POST)
  
          if form.is_valid():
  
              user = form.save(commit=False)
  
              #cleaned (normalized)  data
  
              username = form.cleaned_data['username']
              password = form.cleaned_data['password']
              user.set_password(password)
              user.save()
  
  
              #returns User objects if credentials are correct
  
              user = authenticate(username=username, password=password)
  
              if user is not None:
  
                  if user.is_active:
  
                      login(request,user)
                      return redirect('music:index')
  
          return render(request,self.template_name, {"form": form})
  </code></pre>
  
  <p>and here is my models.py :</p>
  
  <pre><code>from django.db import models
  from django.core.urlresolvers import reverse
  
  class Album(models.Model):
      artist = models.CharField(max_length=250)
      album_title = models.CharField(max_length=500)
      genre = models.CharField(max_length=100)
      album_logo = models.FileField()
  
      def get_absolute_url(self):
          return reverse('music:detail', kwargs={'pk': self.pk})
  
  
      def __str__(self):
          return self.album_title + ' - ' + self.artist
  
  class Song(models.Model):
      album = models.ForeignKey(Album, on_delete=models.CASCADE)
      file_type = models.CharField(max_length=10)
      song_title = models.CharField(max_length=250)
      is_favorite = models.BooleanField(default=False)
      # song_file = models.FileField(null=True)
  
      def __str__(self):
          return self.song_title
  
      def get_absolute_url(self):
          return reverse('music:detail', kwargs={'pk': self.album.id})
  </code></pre>
  
  <p>urls.py:</p>
  
  <pre><code>from django.conf.urls import url
  from . import views
  
  app_name = 'music'
  
  urlpatterns = [
      # /music/
      url(r'^$', views.IndexView.as_view(), name='index'),
      url(r'^register/$', views.UserFormView.as_view(), name='register'),
  
      # /music/album/54
  
      url(r'^album/(?P&lt;pk&gt;[0-9]+)/$', views.DetailView.as_view(), name='detail'),
      # music/album/add
      url(r'album/add/$', views.AlbumCreate.as_view(), name='album-add'),
  
  
  
      # music/album/3/AddSong
      url(r'album/(?P&lt;pk&gt;[0-9]+)/AddSong/$', views.SongCreate.as_view(), name='song-add'),
  
      # music/album/2/update/
      url(r'album/(?P&lt;pk&gt;[0-9]+)/AlbumUpdate/$', views.AlbumUpdate.as_view(), name='album-update'),
  
  
      # music/album/2/delete/
      url(r'album/(?P&lt;pk&gt;[0-9]+)/AlbumDelete/$', views.AlbumDelete.as_view(), name='album-delete'),
  
  ]
  </code></pre>
  
  <p>For creating forms I used Django built-in forms,I had to create one for adding albums and another for adding the album's songs</p>
  
  <p>Here is my album_form.html screenshot
  <a href="https://i.stack.imgur.com/8pm1w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8pm1w.png" alt="enter image description here"></a>
  and here is my form-template.html screenshot:
  <a href="https://i.stack.imgur.com/sa6kt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sa6kt.png" alt="enter image description here"></a>
  and here is my song_form.html screenshot
  <a href="https://i.stack.imgur.com/DBJgE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DBJgE.png" alt="enter image description here"></a></p>