以10为底的int()的无效文字-django-更新 [英] invalid literal for int() with base 10 - django - updated

查看:151
本文介绍了以10为底的int()的无效文字-django-更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是django初学者,并且 我试图做一个像组合框这样的儿童父母(条形取决于城市取决于国家),但我得到了这个错误.

I am a django beginner, and I am trying to make a child-parent like combo box, (bars depends on city depends on country) and I get this error.

更新: 更改了模型和外键的默认值,但仍然存在相同的错误.有什么帮助吗?谢谢!

UPDATE: Changed the model and the default value for the foreign key, but still the same error. Any help? thanks!

这是models.py:

this is models.py:

from django.db import models
from smart_selects.db_fields import ChainedForeignKey

DEFAULT_COUNTRY_ID = 1 # id of Israel
class BarName(models.Model):
    name = models.CharField(max_length=20)
    def __unicode__(self):
        return self.name

class Country(models.Model):
    country = models.CharField(max_length=20)
    def __unicode__(self):
        return self.country

class City(models.Model):
    city = models.CharField(max_length=20)
    country = models.ForeignKey(Country, default=DEFAULT_COUNTRY_ID)
    def __unicode__(self):
        return self.city

class Bar(models.Model):
    country = models.ForeignKey(Country)
    city = ChainedForeignKey(City, chained_field='country' , chained_model_field='country', auto_choose=True)
    name = ChainedForeignKey(BarName, chained_field='city', chained_model_field='city', auto_choose=True)

    def __unicode__(self):
        return '%s %s %s' % (self.name, self.city, self.country)
    class Admin:
        pass

从运行"python manage.py migration"开始:

from running 'python manage.py migrate':

➜  baromatix  python manage.py migrate       
Operations to perform:
  Apply all migrations: admin, bars, contenttypes, auth, sessions
Running migrations:
  .......

    value = self.get_prep_value(value)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 915, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: 'DEFAULT VALUE'

推荐答案

当删除django创建的旧迁移文件时,我解决了此问题.

I solved this issue when deleting the old migrations files that django created.

这篇关于以10为底的int()的无效文字-django-更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆