基数为 10 的 int() 的无效文字 - django - 已更新 [英] invalid literal for int() with base 10 - django - updated
本文介绍了基数为 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.
更新:更改了模型和外键的默认值,但仍然出现相同的错误.有什么帮助吗?谢谢!
这是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 migrate":
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屋!
查看全文