我向 Django 应用程序模型添加了类以创建 mysql 表。我有“下载”表,“歌曲”表中有“下载”列。
当我想同步数据库时,Django 返回错误:
CommandError: One or more models did not validate:
mp3mid.downloads: Reverse query name for field 'song' clashes with field 'songs.downloads'. Add a related_name argument to the definition for 'song'.
为什么不能为表和列赋予相同的名称?
这是我的models.py:
from django_evolution.mutations import *
from django.db import models
class singers(models.Model):
name = models.CharField(max_length = 255)
category = models.ForeignKey(categories)
class songs(models.Model):
name = models.CharField(max_length = 255)
singer = models.ForeignKey(singers)
downloads = models.IntegerField(max_length = 11)
exclusive = models.BooleanField(default = 0)
hit = models.BooleanField(default = 0)
date = models.DateTimeField(auto_now_add = True)
link = models.CharField(max_length = 255)
class downloads(models.Model):
song = models.ForeignKey(songs)
date = models.DateTimeField(auto_now_add = True)