I have some models with CharFields in in my models.py.
e.g.
class MyModel(models.Model):
item_port = models.CharField(max_length=50)`
I have realised that this was a little stupid for a port and changed them all to IntegerFields as follows:
class MyModel(models.Model):
item_port = models.IntegerField(null=True)
I am using sqlite3 in my local dev system and a MySQL type database for deployment. Typically, I manufacture migrations for a new docker instance when deploying from scratch using:
python manage.py makemigrations
and
python manage.py migrate
However, I also have a record of all migrations made to my sqlite3 db in git for reference purposes.
My main question is, can I get away with simply doing a makemigrations/migrate from CharField to IntegerField with existing data in the database (which on client sites will be a MySQL type database OR do I need to do something like this manually?:
https://docs.djangoproject.com/en/1.9/topics/migrations/#data-migrations
Thanks very much.
If you notice that item_port
should be a IntergerField
not a CharField
you can run
./manage.py schemamigration myapp --auto --update
Refering to the South documentation Advanced Commands and Data Migrations
Hope this will help :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With