Tuesday, August 25, 2015

Django 1.7 migrations: Adding one field to User`s model

Hi,

I would like to add one field to User.

I've created new model based on original Django`s user:

 class User(AbstractUser):
    is_verified = models.BooleanField(default=False)

    class Meta:
        db_table = 'auth_user'


Now I'm trying to make migrations, but Django tries to create `auth_user` table from scratch, and this is not what I'm expecting.

I've tried to migrate schema by adding one field:

[...] 
     operations = [
        migrations.AddField('User', 'is_verified', models.BooleanField(default=False)),
    ]

But during migrations Django dies at:

[...]
  File "eggs/Django-1.7.8-py2.7.egg/django/db/migrations/migration.py", line 76, in mutate_state
    operation.state_forwards(self.app_label, new_state)
  File "eggs/Django-1.7.8-py2.7.egg/django/db/migrations/operations/fields.py", line 26, in state_forwards
    state.models[app_label, self.model_name.lower()].fields.append((self.name, field))
KeyError: ('myapp', u'user')


I need to add just one column using builtin migrations. 
How to do that?
This is bug or feature?

BR,
Marcin

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4732d84b-0611-4098-ac9f-01d6bf4d871e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment