1

I edited a fresh migration file to instead of adding a new field, just rename a field that already exists on the Django Model

This was the only change on this field

    migrations.RenameField(
        model_name='my_field',
        old_name='field_old_name',
        new_name='field_new_name',
    ),

But after running manage.py migrate, I notice that a new field was added (with a default field value) and the old one still there

And when running manage.py makemigrations again, it creates a migration to remove the old field

What I can't do, because I would lose the data

Steps:

  • new fields added to model (without removing old one to not break code)
  • manage.py makemigrations
  • code changed to use new field
  • migration file edited to use migrations.RenameField
  • manage.py migrate

1 Answer 1

1

Note: I decided to put this one here, because the problem wasn't that obvious

The issue was that I didn't have write permission on the migration file after generating it

So the editions I did, appeared on the VS Code, but weren't saved on the file So, the migrations applied when running manage.py migrate didn't had the RenameField command

Running sudo chmod -R 775 <project_folder> and sudo chown <user> -R <project_folder> solved

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.