2013-03-14 102 views
0

我有一個models.py文件,下面的類定義:與IpAddressField的Django模型拋出執行syncdb錯誤

from django.db import models 
from bands.models import Genre, Song 

class Lyric(models.Model): 
    """A music lyric""" 
    class Meta: 
     db_table = 'lyric' 
    genre = models.ForeignKey(Genre) 
    song = models.ForeignKey(Song,unique=True) 
    lyric_text = models.TextField() 
    created_at = models.DateTimeField() 
    def __unicode__(self): 
     return "\"" + self.title + "\" by " + self.author 
    def lyric_short(self, length=100): 
     return self.lyric_text[:length] + "..." 

class LyricComment(models.Model): 
    """Comment on a lyric""" 
    class Meta: 
     db_table = 'lyric_comment' 
    lyric = models.ForeignKey(Lyric) 
    text = models.TextField() 
    author = models.CharField(max_length=64) 
    ip = models.IpAddressField() 
    created_at = models.DateTimeField() 
    def __unicode__(self): 
     return "\"" + self.text[:10] + "...\" by " + self.author 
    def text_short(self, length=100): 
     return self.text[:length] + "..." 

在運行時:

$ python manage.py syncdb 

以下錯誤被拋出:

AttributeError: 'module' object has no attribute 'IpAddressField' 

ip = models.IpAddressField()有什麼問題?

回答

3

拼寫爲IPAddressField,大P

+0

太可惜了;)精確 - 這是它。 – ducin 2013-03-14 12:34:28

1

這是拼寫錯誤。

變化ip = models.IpAddressField()ip = models.IPAddressField()