0

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?

Jorge Arévalo
  • 2,858
  • 5
  • 36
  • 44
  • Dunno. But was your "simple syncdb" while you had South installed? (It replaces the syncdb command with it's own slightly-different command with the same name.) Knowing if the problem happens with straight Django versus under South might help narrow down your problem. – Joel Burton Mar 20 '14 at 23:23
  • Yes, it's syncdb with South installed. Didn't know South replaced syncdb. Good to know. I'll delete South from INSTALLED_APPS and try again. Thanks! – Jorge Arévalo Mar 21 '14 at 10:03
  • South uninstalled. Default syncdb still returns the same error. No clues. It's just weird. I updated to Django 1.6.2. Same problem. – Jorge Arévalo Mar 25 '14 at 21:22

1 Answers1

0

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)
Jorge Arévalo
  • 2,858
  • 5
  • 36
  • 44