Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabamnml/3afa9f453c48e51c2dc4be8de65e1aa3 to your computer and use it in GitHub Desktop.
Save gabamnml/3afa9f453c48e51c2dc4be8de65e1aa3 to your computer and use it in GitHub Desktop.
Rename field using migrations in django 1.7
To change a field name in django 1.7+
1. Edit the field name in the model (but remember the old field name: you need it for step 3!)
2. Create an empty migration
$ python manage.py makemigrations --empty myApp
3. Edit the empty migration (it's in the migrations folder in your app folder, and will be the most recent migration) by adding
migrations.RenameField('MyModel', 'old_field_name', 'new_field_name'),
to the operations list.
4. Apply the migration
$ python manage.py migrate myApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment