Django迁移int()的无效文字 [英] Django Migrate invalid literal for int()

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

问题描述

Django 1.7 Python 2.7

Django 1.7 Python 2.7

我已经创建了sqlite数据库,并在管理页面中添加了一些录音到数据库。
然后我更改我的模型,添加了一个ForeignKey。然后我 ./管理makemigrations django询问以前的录音中的默认值,我添加了错误的值(08-808),但我想我需要从另一个添加一些id模型(如1,2,3)存在。

I already made sqlite data base, and added some recordings to data base in admin page. Then i change my models, added a ForeignKey. Then i ./manage makemigrations django asked about default values in previous recordings, i added wrong value ("08-808"), but i think i need added some id from another model (like 1,2,3 which exist).

然后(现在)我运行 ./管理迁移,我有一个错误:

Then (and now) i run ./manage migrate, i have a error:

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

Operations to perform:
  Apply all migrations: admin, contenttypes, lab, auth, sessions
Running migrations:
  Applying lab.0004_auto_20141017_0226...Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 160, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 63, in migrate
    self.apply_migration(migration, fake=fake)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 97, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 107, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 37, in database_forwards
    field,
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/backends/sqlite3/schema.py", line 160, in add_field
    self._remake_table(model, create_fields=[field])
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/backends/sqlite3/schema.py", line 74, in _remake_table
    self.effective_default(field)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 183, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1722, in get_db_prep_save
    return self.related_field.get_db_prep_save(value, connection=connection)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 627, in get_db_prep_save
    prepared=False)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 907, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/home/denis/WebDir/laboratory1/env/local/lib/python2.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: '08-506'


推荐答案

int()with base 10:'08 -506'。这听起来不像我的int。检查您的迁移(lab.0004_auto_20141017_0226)并使用有效的int修改该值。或者将字段类型更改为char或某些东西。

int() with base 10: '08-506'. That does not sound like an int to me. Check your migration (lab.0004_auto_20141017_0226) and modify that value with a valid int. Either that or change the field type to char or something.

这篇关于Django迁移int()的无效文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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