Question

I have a Django model like this:

class Company(models.Model):
    name=models.CharField(max_length=256, default=''),
    user=models.ForeignKey(User),
    logo=models.ImageField(upload_to='logos')

    def __unicode__(self):
        return unicode(self.name)

after running syncdb, I get this PostgreSQL table

CREATE TABLE myapp_company (
    id integer NOT NULL,
    logo character varying(100) NOT NULL
);

So, no name field, neither user id. The same thing happens with other model classes: missing fields. And look random. For example, this is weird. This model

class MapLayer(models.Model):
    cartodb_layer = models.ForeignKey('CartoDBLayer'),
    work_map = models.ForeignKey('WorkMap'),
    overlap = models.BooleanField(default=False),
    min_zoom = models.IntegerField(default=4),
    max_zoom = models.IntegerField(default=14),
    opacity = models.FloatField(default=0.6),
    anti_aliasing = models.FloatField(default=0.5)

Generates this PostgreSQL table

CREATE TABLE myapp_maplayer (
    id integer NOT NULL,
    anti_aliasing double precision NOT NULL
);

So, why just the id and the last field (a float), but not any other field??

Same problem trying to run a schemamigration --initial via South 0.8.2. But the fact even a simple syncdb fails makes me think it's not a South issue.

My software versions:

  • Django 1.5.4
  • South 0.8.2
  • PostgreSQL 9.1 + PostGIS 2

Any clues?

Was it helpful?

Solution

Solved. Stupidest mistake ever. The problem was the commas. So, I need to replace

class Company(models.Model):
    name=models.CharField(max_length=256, default=''),
    user=models.ForeignKey(User),
    logo=models.ImageField(upload_to='logos')

    def __unicode__(self):
        return unicode(self.name)

With

class Company(models.Model):
    name=models.CharField(max_length=256, default='')
    user=models.ForeignKey(User)
    logo=models.ImageField(upload_to='logos')

    def __unicode__(self):
        return unicode(self.name)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top