Guilherme
Guilherme

Reputation: 1835

Django migrations.RenameField creating new field instead of renaming existing one

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:

Upvotes: 1

Views: 367

Answers (1)

Guilherme
Guilherme

Reputation: 1835

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

Upvotes: 1

Related Questions