Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGilang Ilhami
12,045 PointsReceive an error when trying to migrate and not all test passed
When i was trying to check migrations using 'python manage.py make migrations songs', it was fine. But when i tried to migrate it 'python manage.py migrate songs', i received an error
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before
trying to migrate apps individually.
And when i tried to test the module, not all test passed. But i don't really understand the error here and have been trying to find a solution for a very long time.
File "/usr/local/pyenv/versions/3.5.0/lib/python3.5/site-packages/django/db/models/query.py", l
ine 399, in create
obj = self.model(**kwargs)
File "/usr/local/pyenv/versions/3.5.0/lib/python3.5/site-packages/django/db/models/base.py", li
ne 451, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'artist' is an invalid keyword argument for this function
----------------------------------------------------------------------
Ran 5 tests in 0.048s
FAILED (errors=4)
Destroying test database for alias 'default'...
Can somebody please help me with this
from django.db import models
class Performer(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
class Song(models.Model):
title = models.CharField(max_length=255),
artist = models.CharField(max_length=255),
performer = models.ForeignKey('Performer')
length = models.IntegerField(default=0)
def __str__(self):
return '{} by {}'.format(self.title, self.artist)
from django.shortcuts import get_object_or_404, render
from .models import Song, Performer
def song_list(request):
songs = Song.objects.all()
return render(request, 'songs/song_list.html', {'songs':songs})
def song_detail(request, pk):
song = get_object_or_404(Song, pk=pk)
return render(request, 'songs/song_detail.hmtl', {'songs':detail})
def performer_detail(request, pk):
performer = get_object_or_404(Performer, pk=pk)
performer.song_set.all()
return render(request, 'songs/performer_detail.html', {'songs':performer})
{% extends 'base.html' %}
{% block title %}{{ performer }}{% endblock %}
{% block content %}
<h2>{{ performer }}</h2>
{% endblock %}