Skip to content Skip to sidebar Skip to footer

Invalid Literal For Int() With Base 10: - Django - Python

I was trying to make the author of a news be automatically picked when the news is created. This is my code: Model: from django.db import models from ckeditor.fields import RichTex

Solution 1:

Your model shows news_author = models.CharField, but the error suggests you had news_author = models.ForeignKey(User) at some stage instead. Using a foreign key is usually better, and I would name it author = models.ForeignKey(User), since you don't have to repeat news from the model.

You've now got a mismatch between the database and your models files, and fixing that can be tricky. If you're in development and don't have any important data in the db, the simplest thing would be to delete the migrations, recreate the database, and then run makemigrations and migrate again.


Solution 2:

I think you should rest your migration ,run these commands into your command line (terminal) in your project path :

find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc"  -delete

after that migrate your project again:

python manage.py makemigrations APP_NAME
python manage.py migrate

and you attention when you migrate database, your database doesn't open in other application like database viewer.


Post a Comment for "Invalid Literal For Int() With Base 10: - Django - Python"