我很新的Django,刚刚得到了一个工作,涉及维护和添加功能,我没有设计的网站,所以我仍然有点困惑的结构,什么不该项目。该网站正在使用South进行数据库迁移,并且我已经利用它向项目添加新的应用程序。我现在遇到的麻烦是我需要删除模型中的某个字段,因为它不再需要,并且在管理页面上需要填写它。从我对Django的理解到目前为止,它似乎是一个自定义字段。它在它自己的单独的库应用程序中被定义为这样(仍然不确定这是否是正确的术语)。自定义南迁移与自定义字段 - Django
class Genre(models.Model):
name = models.CharField(max_length=255)
def __unicode__(self):
return u"%s" % self.name
以下是使用自定义字段的模型,如果有帮助的话。
class Entry(models.Model):
artist = d51fields.ForeignKey(Artist, instantiate_fn=instant_artist)
album = d51fields.ForeignKey(Album, js_methods=['match_artist_and_startswith'], instantiate_fn=instant_album)
track = d51fields.ForeignKey(Track, js_methods=['match_album_and_startswith'], instantiate_fn=instant_track)
genre = models.ForeignKey(Genre)
submitted = models.DateTimeField(auto_now_add=True)
is_rotation = models.BooleanField()
dj = models.ForeignKey(DJ)
show = models.ForeignKey(Show, null=True, blank=True)
objects = EntryManager()
def __unicode__(self):
return "%s [%s]" % (self.artist, self.track)
class Meta:
verbose_name = "entry"
verbose_name_plural = "entries"
我已经看了迁移自定义字段的文档,但它是所有真正困惑我,所以我找了一些更多的帮助。我只想摆脱持有Genre字段的表格,并清除与其关联的外键的依赖关系。你认为我应该为South编写一些自定义规则并使用迁移,或者只是尝试在Postgresql中手动执行。我试着用Postgres来做这件事,但我失败了。
任何指导将不胜感激。如果你想了解更多有关情况的信息,只需询问我可以将其添加到帖子中。我有一种感觉,我需要处理很多依赖项,但希望有一个简单的解决方法。
此外,如果有人知道如何获得好的数据库结构的好看法。
非常感谢。你们所有人都很棒。
EDIT1
在这里我得到了什么,当我删除了ForeignKeys然后跑去
manage.py schemamigration logs --auto
! Cannot freeze field 'logs.entry.artist'
! (this field has class d51_admin_autofk.fields.ForeignKey)
! Cannot freeze field 'logs.entry.album'
! (this field has class d51_admin_autofk.fields.ForeignKey)
! Cannot freeze field 'logs.entry.track'
! (this field has class d51_admin_autofk.fields.ForeignKey)
! South cannot introspect some fields; this is probably because they are custom
! fields. If they worked in 0.6 or below, this is because we have removed the
! models parser (it often broke things).
我不能完全确定我下一步应该采取什么样的行动。我研究了南方的文档,并且不清楚如何编写这样的迁移规则。
我试着你说的,我得到了一个关于自定义字段不能被冻结的错误,我编辑了我的帖子以显示输出。 – thebeagle
哦,我很抱歉,再次查看您的代码,看起来您确实有自定义字段。那么,我知道有很多方法可以告诉南方如何处理自定义字段,但我必须阅读关于该文档的文档。就你的情况而言,例如,让南方忽略这些领域应该没问题(因为你没有对它们做任何改变)。你可能想看看http://south.aeracode.org/docs/tutorial/part4.html – koniiiik
非常感谢。我终于弄清楚了。干杯。 – thebeagle