Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming Django model field

I'm trying to convert one of my model fields (units) from FloatField to an IntegerField.

My strategy is this:

  1. Add '_units' field (IntegerField)
  2. Copy data from 'units' to '_units'
  3. Remove 'units'
  4. Rename '_units' as 'units'

Migrations for steps 1 - 3 run fine but at Step 4 I get an error when I run the tests:

django.db.utils.OperationalError: no such column: myapp_mymodel._units

For this step I made an empty migration then added to the operations;

migrations.RenameField('MyModel', '_units', 'units')  

Where am I going wrong?

like image 562
Morgan P Avatar asked Jun 21 '16 10:06

Morgan P


1 Answers

Use migrations.AlterField it will do all 4 steps in one.

like image 140
Sardorbek Imomaliev Avatar answered Sep 28 '22 18:09

Sardorbek Imomaliev