Reputation: 59
i made a model of music with 2 classes album and song and code is provided below but my error code shows- Album-models.ForeignKey(Album,on_delete=models.CASCADE) TypeError: unsupported operand type(s) for -: 'ModelBase' and 'ForeignKey'
i just started django so go easy on the answers
from django.db import models
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.Charfield(max_length=1000)
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)
Upvotes: 0
Views: 314
Reputation: 6404
You need to change Charfield
to CharField
Also in Song
model correct this:
album=models.ForeignKey(Album,on_delete=models.CASCADE)
Upvotes: 0
Reputation: 11451
Actually its CharField()
instead of Charfield()
, because django follows Capital Camel Casing
so you Album
model should look like
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.CharField(max_length=1000)
Upvotes: 1