3

I've got the following Django class:

class Contacto(models.Model):
    responsable_documento = models.CharField(primary_key=True, max_length=40)
    responsable_tipo_documento = models.CharField(max_length=20)
    responsable_nombre = models.CharField(max_length=50, blank=True)
    responsable_apellido = models.CharField(max_length=60, blank=True)
    responsable_telefono = models.CharField(max_length=20, blank=True)
    responsable_telefono_particular = models.CharField(max_length=20, blank=True)
    responable_email_uno = models.EmailField()
    responsable_email_dos = models.EmailField()
    responsable_email_tres = models.EmailField()
    cueanexo = models.PositiveIntegerField(null=True)

    class Meta:
        unique_together = (
            ('responsable_documento', 'responsable_tipo_documento', 'alumno_documento', 'alumno_tipo_documento'),
        )
        verbose_name_plural = 'contactos'

And I am trying to rename some fields:

class Contacto(models.Model):
    responsable_documento = models.CharField(primary_key=True, max_length=40)
    responsable_tipo_documento = models.CharField(max_length=20)
    responsable_nombre = models.CharField(max_length=50, blank=True)
    responsable_apellido = models.CharField(max_length=60, blank=True)
    responsable_telefono = models.CharField(max_length=20, blank=True)
    responsable_telefono_celular = models.CharField(max_length=20, blank=True)
    responable_email1 = models.EmailField()
    responsable_email2 = models.EmailField()
    responsable_email3 = models.EmailField()
    cue_anexo = models.PositiveIntegerField(null=True)

    class Meta:
        unique_together = (
            ('responsable_documento', 'responsable_tipo_documento', 'alumno_documento', 'alumno_tipo_documento'),
        )
        verbose_name_plural = 'contactos'

This results in the following migration:

class Migration(migrations.Migration):

    dependencies = [
        ('datos_basicos', '0008_auto_20180813_1505'),
    ]

    operations = [
        migrations.RenameField(
            model_name='contacto',
            old_name='cueanexo',
            new_name='cue_anexo',
        ),
        migrations.RenameField(
            model_name='contacto',
            old_name='responable_email_uno',
            new_name='responable_email1',
        ),
        migrations.RenameField(
            model_name='contacto',
            old_name='responsable_email_dos',
            new_name='responsable_email2',
        ),
        migrations.RenameField(
            model_name='contacto',
            old_name='responsable_email_tres',
            new_name='responsable_email3',
        ),
        migrations.RenameField(
            model_name='contacto',
            old_name='responsable_telefono_particular',
            new_name='responsable_telefono_celular',
        ),
    ]

When I try to apply said migration the following error occurs:

Running migrations:
  Applying datos_basicos.0009_auto_20180813_1731...Traceback (most recent call last):
  File "/home/desarrollo/.local/share/virtualenvs/censo_estudiantil-86GgnGcQ/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  psycopg2.ProgrammingError: syntax error at or near "WITH ORDINALITY"
  LINE 6:                     FROM unnest(c.conkey) WITH ORDINALITY co...

Do anyone know what could be causing this error?

Ralf
  • 16,086
  • 4
  • 44
  • 68
Guido
  • 81
  • 2
  • 9
  • 1
    I had this error when I was on Postgres 9.3. I was able to run migrations after switching to Postgres 9.4. – evan_schmevan Nov 29 '18 at 02:48
  • 1
    A gotcha for me was that Ubuntu preserved my database versions when I upgraded, so I didn't notice the server version was back at 9.1. There are some manual steps required to update the database to the current version, so even though Postgres10 was installed, I was still using 9.1. This helped a lot: https://gorails.com/guides/upgrading-postgresql-version-on-ubuntu-server – Fiid Mar 22 '19 at 16:55

3 Answers3

6

I got the same error message after switching to Django 2.1, updating my Postgres version fixed this for me. But there was a drop of support in the 2.1 release https://docs.djangoproject.com/en/2.1/releases/2.1/#dropped-support-for-postgresql-9-3

flo
  • 76
  • 2
  • What tripped me up (and what led me to this page) is that Travis CI uses Postgres 9.2 as a default, but thankfully you can specify other versions: https://docs.travis-ci.com/user/database-setup/#using-a-different-postgresql-version – Wilhelm Klopp Mar 17 '19 at 18:32
3

I think it's a django bug. In my case, downgrading to version 2.0 worked. Bests. José

José
  • 1,774
  • 1
  • 17
  • 21
0

The bug is for django version greater than 2.0.Downgrading the django version to 2.0 and Postgres version same as 9.3 worked for me.