title: Django:ValueError: invalid literal for int() with base 10
body: <p>I'm getting a value error, when I'm trying to add new data to my database.</p>
  
  <p>My models.py:</p>
  
  <pre><code># -*- coding: utf-8 -*-
  from __future__ import unicode_literals
  
  from django.db import models
  from django.contrib.auth.models import User
  
  DEFAULT_ROLE_ID=1
  class UserProfile(models.Model):
    user= models.OneToOneField(User)
    avatar= models.ImageField(upload_to='Images/users', verbose_name='Image')
    rating=models.IntegerField(default=0)
    karma=models.IntegerField(default=0)
  
    def __unicode__(self):
      return unicode(self.user)
  
  class Room(models.Model):
    title=models.CharField(max_length=63,default='test')
    time_creation=models.DateTimeField('Time of room creation')
    users=models.ManyToManyField(UserProfile)
  
    def __unicode__(self):
      return unicode(self.title)
  
  class Game(models.Model):
    title=models.CharField(max_length=63,default='test')
    time_creation=models.DateTimeField('Время создания')
    room=models.ForeignKey(Room)
  
    def __unicode__(self):
      return unicode(self.title)
  
  class SecretWord(models.Model):
    word=models.CharField(max_length=255)
    game=models.ForeignKey(Game)
  
    def __unicode__(self):
      return unicode(self.word)
  
  class UserRole(models.Model):
    PLAYER = 'PL'
    LIDER = 'LID'
    ROLE_CHOICES = (        
      (LIDER, 'Lider'),
      (PLAYER, 'Player'),
    )
    user=models.ForeignKey(UserProfile,default=1)
    game=models.ForeignKey(Game,default=1)
    role = models.CharField(max_length=3,choices=ROLE_CHOICES,default=LIDER)
  
    def __unicode__(self):
      return unicode(self.role)    
  
  class Message(models.Model):
    text=models.TextField(max_length=2047)
    time_creation=models.DateTimeField('Time of room creation')
    room=models.ForeignKey(Room)
    user=models.ForeignKey(UserProfile)
    user_role=models.ForeignKey(UserRole, default=DEFAULT_ROLE_ID)
  
    def __unicode__(self):
      return unicode(self.text)
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>  Applying hat.0030_auto_20160421_1632...Traceback (most recent call last):
    File "manage.py", line 10, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
      utility.execute()
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
      output = self.handle(*args, **options)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
      executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
      self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
      state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
      state = migration.apply(state, schema_editor)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
      operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
      field,
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/mysql/schema.py", line 50, in add_field
      super(DatabaseSchemaEditor, self).add_field(model, field)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 382, in add_field
      definition, params = self.column_sql(model, field, include_default=True)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 145, in column_sql
      default_value = self.effective_default(field)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 210, in effective_default
      default = field.get_db_prep_save(default, self.connection)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 915, in get_db_prep_save
      return self.target_field.get_db_prep_save(value, connection=connection)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 728, in get_db_prep_save
      prepared=False)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 968, in get_db_prep_value
      value = self.get_prep_value(value)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 976, in get_prep_value
      return int(value)
  ValueError: invalid literal for int() with base 10: 'Player'
  </code></pre>
  
  <p>I have tried to comment out different parts of code, but didn't even understand in which exactly place, where I use data from UserRole model, I made a mistake.</p>
  
  <p>P.S.And I just noticed: after I change my code and using 'python manage.py migrate' I get this error: </p>
  
  <pre><code>Operations to perform:
  Apply all migrations: admin, contenttypes, hat, auth, sessions
  Running migrations:
    Applying hat.0030_auto_20160421_1632...Traceback (most recent call last):
    File "manage.py", line 10, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
      utility.execute()
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
      output = self.handle(*args, **options)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
      executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
      self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
      state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
      state = migration.apply(state, schema_editor)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
      operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
      schema_editor.create_model(model)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 284, in create_model
      self.execute(sql, params or None)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 110, in execute
      cursor.execute(sql, params)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
      return super(CursorDebugWrapper, self).execute(sql, params)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
      return self.cursor.execute(sql, params)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
      six.reraise(dj_exc_type, dj_exc_value, traceback)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
      return self.cursor.execute(sql)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 112, in execute
      return self.cursor.execute(query, args)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
      self.errorhandler(self, exc, value)
    File "/home/aska1/prog/prog/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
      raise errorclass, errorvalue
  django.db.utils.OperationalError: (1050, "Table 'hat_usergame' already exists")
  </code></pre>
  
  <p>But the table 'usergame' has another name - 'UserRole' now. I have so habituated to this error, that even don't noticed that. I usually use command 'python manage.py reset_db' from  <a href="http://django-extensions.readthedocs.org/en/latest/command_extensions.html" rel="nofollow">django-extensions</a> and everything works after it. As I understand, I should delete old migrations, shouldn't I? Maybe it can fix up my another error?</p>
  
  <p>I'm a novice in Django, so maybe I simply don't understand elementary things.</p>
  
  <hr>
  
  <p>In result the problem was solved by deleting migrations, beginning with migration number 0030, when everything went wrong.</p>
  
  <p>Viewing list of migrations:</p>
  
  <pre><code>python manage.py migrate --list
  app
  (*) 0001_initial
  (*) 0002_auto__...
  (*) 0003_auto__...
  (*) 0004_auto__...
  </code></pre>
  
  <p>Applying the last correct migration and deleting the following:</p>
  
  <pre><code>./manage.py migrate app 0003
  rm app/migrations/0004*
  </code></pre>