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

时间:2018-08-13 17:42:27

标签: python django python-3.x migration django-2.0

我有以下Django类:

<table>
  <colgroup>
    <col>
    <col>
  </colgroup>
  <thead>
    <tr>
      <th>Column A</th>
      <th>Column B</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>2</td>
    </tr>
  </tbody>
</table>

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

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

有人知道什么可能导致此错误吗?

3 个答案:

答案 0 :(得分:6)

切换到Django 2.1后,我得到了相同的错误消息,更新了我的Postgres版本后,为我解决了这个问题。但是2.1版本中的支持下降了 https://docs.djangoproject.com/en/2.1/releases/2.1/#dropped-support-for-postgresql-9-3

答案 1 :(得分:3)

我认为这是一个django错误。 就我而言,降级到2.0版是可行的。最好的。乔斯

答案 2 :(得分:0)

该错误是针对Django 2.0或更高版本的。将Django版本降级至2.0和与9.3相同的Postgres版本对我有用。