Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Migrate invalid literal for int()

Django 1.7 Python 2.7

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'
like image 236
Denis Avatar asked Dec 12 '22 03:12

Denis


1 Answers

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.

like image 156
cdvv7788 Avatar answered Dec 22 '22 17:12

cdvv7788