Django 1.8 migration unable to cast column id to integer

后端 未结 2 1991
無奈伤痛
無奈伤痛 2021-02-12 22:56

I\'m migrating my site from an SQLite backend to a Postgres backend. We\'ve been running native-Django style migrations (i.e., not South) from the beginning of the project. Most

2条回答
  •  没有蜡笔的小新
    2021-02-12 23:13

    The problem is the migration from Process.milestone as a boolean field to Process.milestone as a foreign key. Postgres doesn't wait for a migration to fail on uncastable data. It wants a rule to alter the table in advance.

    If you don't intend any sort of data migration between two fields, the easiest option is to simply drop and add the field. In this specific case, it would mean changing the operations as follows:

    operations = [
        migrations.RemoveField(
            model_name='process',
            name='milestone'
        ),
        migrations.AddField(
            model_name='process',
            name='milestone',
            field=models.ForeignKey(to='processes.Milestone'),
        ),
        migrations.AlterModelOptions(
            name='process',
            options={'ordering': ['milestone', 'sequence'], 'verbose_name_plural': 'processes'},
        )
    ]
    

提交回复
热议问题