我们在具有外键约束的表上遇到此问题。对于造成此问题的表,我们完全无限制地复制了表数据,只是将数据复制到新表中,并且一切正常。但是,我们希望将表与关系和实际约束一起使用。
我们的 models.py
class NewsSerialiser(serializers.HyperlinkedModelSerializer):
class Meta:
model = News
fields = ('news_id', 'news_source', 'news_title', 'news_description', 'news_publication_date', 'news_link')
class NewsViewSet(viewsets.ModelViewSet):
queryset = News.objects.all()
serializer_class = NewsSerialiser
我们的URlS.py
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework import routers
from note.note_api import NewsViewSet
# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'notes', NewsViewSet, 'news')
urlpatterns = router.urls
问题:
Could not resolve URL for hyperlinked relationship using view name "source-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.
此错误似乎在具有外键约束的表上持续存在。
非常感谢任何建议或支持。