I change my model field from Charfiled() to GenericIPAddressField()
ip = models.GenericIPAddressField()
and use django 1.7 migrate
./manage.py makemigrations core
./manage.py migrate
But there is error:
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "ip" cannot be cast automatically to type inet
HINT: Specify a USING expression to perform the conversion.
I try this,but not work:
ALTER TABLE core_message ALTER COLUMN ip TYPE inet USING (ip::inet);
error:
ERROR: invalid input syntax for type inet: ""
What can I do now?
Please help me Thank you!
you can either: temporarily remove your migration, execute python manage.py migrate, add again your migration and re-execute python manage.py migrate. Use this case if the migrations refer to different models and you want different migration files for each one of them.
Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They're designed to be mostly automatic, but you'll need to know when to make migrations, when to run them, and the common problems you might run into.
So the difference between makemigrations and migrate is this: makemigrations auto generates migration files containing changes that need to be applied to the database, but doesn't actually change anyhting in your database. migrate will make the actual modifications to your database, based on the migration files.
one quick fix will be to drop and create the field:
ip
ip
with the new field typeI did this in production and restored the data with a previous csv backup and an python script of a few lines a code.
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