Django 2.0.7执行重命名字段迁移时出现语法错误

2024-09-29 23:21:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下Django课程:

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'

我正在尝试重命名一些字段:

^{pr2}$

这将导致以下迁移:

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',
        ),
    ]

当我尝试应用上述迁移时,出现以下错误:

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...

有人知道是什么导致了这个错误吗?在


Tags: nametruenewmodelmodelsemailmigrationslength
3条回答

在切换到django2.1之后,我收到了同样的错误消息,更新Postgres版本为我修复了这个问题。但是2.1版本的支持率有所下降 https://docs.djangoproject.com/en/2.1/releases/2.1/#dropped-support-for-postgresql-9-3

这个bug是针对大于2.0的django版本的,将django版本降级到2.0和Postgres版本(与9.3相同)对我很有用。在

我想是个django虫。 在我的例子中,降级到2.0版本是可行的。最好的。何塞

相关问题 更多 >

    热门问题