简体   繁体   中英

ValueError: invalid literal for int() with base 10: '' | Django

I'm using Django to build an ecommerce webapp . I wrote this code in models.py

from django.db import models


# Create your models here.
class Product(models.Model):
    product_id = models.AutoField
    product_name = models.CharField(max_length=50)
    category = models.CharField(max_length=50, default="")
    subcategory = models.CharField(max_length=50, default="")
    price = models.IntegerField(default=0)
    desc = models.CharField(max_length=300)
    pub_date = models.DateField()
    image = models.ImageField(upload_to='mainShop/images', default="")

Then, I performed makemigrations using

python manage.py makemigrations

which produced the following

D:\Projects\PyCharm Projects\VeroniCart\home>python manage.py makemigrations
No changes detected

Then I did

python manage.py migrate

This gave me the error:

ValueError: invalid literal for int() with base 10: ''

I'm also attaching a log file with the complete error. Any help appreciated!

Issue solved . All I did was I deleted all files from my app's migrations directory (except migrations/init.py) and deleted the database file db.sqlite3 from the project directory. Then I repeated the previous steps (makemigrations and migrate).

Django again created all migrations files and a new db.sqlite3 file, so this worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM