[Fixed]-Django:ValueError: invalid literal for int() with base 10

1👍

So, one thing is for sure. The error that you are getting while running migrations, is because django is reading one of the files that makemigrations would have made and in which, there would have been ‘usergame’ table. Though, retracting migrations could be a pain sometimes (deleting old migrations file is one way), but by running reset_db command, you are effectively dropping the db and recreating it. What, I would generally do in this case is, first drop the db, then run makemigrations and then run migrations. But, in this case, run makemigrations only when you are sure about your models. Finalize your models, run python manage.py makemigrations and subsequently migrate command.

Secondly, you wrote in your second paragraph, that after you changed your code and ran migrations, you got the error. Now, since looking at your (modified) models and relating the error that you got (invalid literal), it’s a bit difficult to understand the reason behind your error (because your model seems fine). The best possible theory, that I came up with was: since ValueError: invalid literal for int() with base 10 comes when in a field which accepts integers and and in that field, you are supplying floats. So, either convert that field to FloatField or supply correct values in that field (I am sure you must be aware of this fact, but just writing just in case: even a 8.0000 is not an int, it’s a float).

Take a shot at retracting your migrations and possibly, when the new models get into your db, hopefully the problem might resolve.

Leave a comment