Duplicate column name

后端 未结 7 1793
栀梦
栀梦 2021-02-05 15:22

I\'ve changed my models an then I tried to migrate them, but got this error:

python manage.py migrate
Operations to perform:
  Apply all migrations: admin, conte         


        
7条回答
  •  日久生厌
    2021-02-05 16:17

    When I had this issue, I had to go to each migration that said it had a duplicate column and merge the 0002_*.py migration file with the 0001_initial.py migration file.

    1. Copy all the operations in the operations = [] list and paste them into the operations = [] list in the 0001_initial.py file.

    migrations.AddField(
        model_name='words',
        name='short_description_eng',
        field=models.CharField(blank=True, default='', max_length=100, verbose_name='Условное обозначение Eng'),
    ),
    migrations.AddField(
        model_name='words',
        name='short_description_rus',
        field=models.CharField(blank=True, default='', max_length=100, verbose_name='Условное обозначение Рус'),
    ),
    migrations.AddField(
        model_name='words',
        name='short_description_tur',
        field=models.CharField(blank=True, default='', max_length=100, verbose_name='Условное обозначение Tür'),
    ),
    migrations.AlterField(
        model_name='words',
        name='audio',
        field=models.FileField(blank=True, upload_to='audio', verbose_name='Озвучка'),
    ),
    migrations.AlterField(
        model_name='words',
        name='english',
        field=models.TextField(blank=True, default='', verbose_name='English'),
    ),
    migrations.AlterField(
        model_name='words',
        name='russian',
        field=models.TextField(blank=True, default='', verbose_name='Русский'),
    ),
    migrations.AlterField(
        model_name='words',
        name='title',
        field=models.CharField(max_length=100, unique=True, verbose_name='Слово'),
    ),
    migrations.AlterField(
        model_name='words',
        name='turkish',
        field=models.TextField(blank=True, default='', verbose_name='Türkçe'),
    ),
    

    2. If you had other dependencies besides 0001_initial, you would copy all the lines in dependencies = [] (except the line that says('myapp', '0001_initial'),) migrations from the list of dependencies and paste them into the 0001_initial.py migration file.

    Important Note: Make sure you grab any import dependencies too. I had no issues after following those simple steps.

提交回复
热议问题