尝试syncdb时出现Django语法错误

时间:2012-07-10 00:38:13

标签: django

我正在从HackedExistence做一个教程,在尝试syncdb时遇到以下错误:

class Beer(models.Model):
    ^

SyntaxError: invalid syntax

我在virtualenv上运行Django

代码如下:

BEER_CHOICES = (
    ('D', 'Domestic'),
    ('I', 'Import'),

class Beer(models.Model):

    name = models.CharField(max_length=200)
    slug = models.Slugfield(unique=True)
    brewery = models.foreignKey('Brewery')
    locality = models.CharField(max_length=1, choice=BEER_CHOICES)
    description = models.TextField(blank=True)

    def __unicode__(self):
        return self.name

class Brewery(models.Model):

    name    = models.CharField(max_length=200)
    slug    = models.Slugfield(unique=True)
    description = models.TextField(blank=True)

    def __unicode__(self):
        return self.name

1 个答案:

答案 0 :(得分:4)

Choices should be defined in a list or tuple of two-tuples
你已经忘记了元组的最终结果。

BEER_CHOICES = ( 
    ('D', 'Domestic'), 
    ('I', 'Import'),
) # <- missing end-bracket