I recently ported from raw php to django and had to incorporate my legacy database into it. I used the inspectdb
command to construct the models out of the database and everything was working fine.
Recently I decided to add the functionality of like
and set to favorite
. So I added a new table as shown below.
class SongCollection(models.Model):
song_name = models.TextField()
song_type = models.CharField(max_length=765)
likes = models.IntegerField(default=0)
class Meta:
db_table = u'songcollection'
class likeSong(models.Model):
user = models.ForeignKey(User)
company = models.ForeignKey(SongCollection)
The first one is my original class
and the other one is for storing which user has liked which song. I am using the exact structure for like in my other applications completely developed in django
and they are working fine. But when I try to add an object to likeSong
I get the following error.
Cannot add or update a child row: a foreign key constraint fails
I tried to add this object from MySql command line as well, in order to check if this was a Django
error but it failed there also. Can anybody help me in understanding in what actually is wrong here?