ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-07-27 01:58:06  阅读:286  来源: 互联网

标签:python python-3-x django migration django-2-0


我有以下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'

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

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'

这导致以下迁移:

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

有谁知道可能导致此错误的原因是什么?

解决方法:

切换到Django 2.1后,我得到了相同的错误信息,更新我的Postgres版本为我修复了这个问题.但是在2.1版本中有一点支持
https://docs.djangoproject.com/en/2.1/releases/2.1/#dropped-support-for-postgresql-9-3

标签:python,python-3-x,django,migration,django-2-0
来源: https://codeday.me/bug/20190727/1549445.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有