Skip to content

Can not use django migrations to rename field. #195

@luoxiaopeng

Description

@luoxiaopeng
  1. Create a demo project(eg. mysite, https://docs.djangoproject.com/en/4.0/intro/tutorial01/)
  2. Change models.py and migrations(No problem)
from django.db import models
from sortedm2m.fields import SortedManyToManyField

class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    choice_order = SortedManyToManyField("Choice", related_name='choice_order', blank=True)

class Choice(models.Model):
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
  1. Make some data for Question and Choice.
  2. change choice_order to choices (models.py)
  3. python3 manage.py makemigrations (will generate something like this migrations.RenameField(
    model_name='question',
    old_name='choice_order',
    new_name='choices',
    ))
  4. python3 manage.py migrate
  5. django.db.utils.IntegrityError: NOT NULL constraint failed: polls_question_choices.sort_value

I don't know how to contact you and I alse don't know whether django-sortedm2m support migrations.RenameField.
Could you have a look this problem when you're free.
Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions