Django迁移int()的无效文字

时间:2014-10-17 12:27:07

标签: python django django-models

Django 1.7 Python 2.7

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

然后(现在)我运行./manage migrate,我有一个错误:

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'

1 个答案:

答案 0 :(得分:8)

int()with base 10:&#39; 08-506&#39;。这对我来说听起来不像是一个int。检查您的迁移(lab.0004_auto_20141017_0226)并使用有效的int修改该值。或者将字段类型更改为char或其他内容。