Tuesday, August 25, 2015

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

This might be related to the difficulties of migrating an existing project to a custom user model. I'm not sure the steps to workaround the problem. We have an open ticket to recommend starting off a project with a custom user model to avoid this problem [1]. Sorry I can't be of more help.

[1] https://code.djangoproject.com/ticket/24370

On Tuesday, August 25, 2015 at 7:51:08 AM UTC-4, marcin....@gmail.com wrote:
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/336848e0-5ce2-41fb-b883-35c1fe38ad79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment