[Django]-Django ORM migration giving "ValueError: invalid literal for int()" on IntegerField

3👍

The migration failed in python, so it never made it to the database. You should leave everything as is, and go into the migrations/ folder and delete the migration which adds the flowertype field (it’s going to be the most recent one). Then run python manage.py makemigrations again, but make sure you have flowertype = IntegerField(default=1) (not default='1') set in the model definition.

EDIT for further explanation:

When you run the command makemigrations, django inspects all of your model definitions in python and compares them against what is in the database. If the two don’t match, django will create a migration file which will update the database to reflect the model definitions as they are defined in your python code. This is what the migrate command does, it runs all of the new migration files.

So the first time you ran makemigrations, a migration file was created which added a column to the Order table, and tried to set the value of every row to 'something'.

This immediately failed, since it was trying to put a str into and int field.

Since it failed, unless you delete the file, any and everytime you run migrate, django was going to keep trying to run that script. There were two options 1) You could’ve just went in and edited the migration file by hand, or 2) You can just delete that migration file and re-create it once you have your model definitions fixed.

👤dursk

Leave a comment