Unable to migrate data using django 1.5 user user class

I have many applications with historical southern initial migrations that I would like to convert to django 1.5. Therefore, I changed all the orm ['auth.User'] links in the user migration files, but when I try to start these migrations, I get the following error:

Migration error: django_notify: 0001_initial KeyError: "The" customuser "model from application profiles is not available in this migration."

The emerging issue is this: http://bpaste.net/show/2CwaYrlNifNTd5gcHUfK/

My custom user class:

class CustomUser(AbstractUser): image = models.ImageField(_('Image Field'), upload_to='user_images') 

I also cannot convert my'profiles application to the south using the convert_to_south command. I get the following error:

Creating init .py in '/ Users / tejinder / Projects / basidia / apps / profiles / migrations' ...

  • Added .CustomUser model profiles

    • Added M2M table for groups in profiles. User interface

    • Added M2M table for user_permissions on profiles.CustomUser

Created by 0001_initial.py. Now you can apply this migration with: ./ manage.py migrate profiles

CommandError: one or more models were not checked: auth.user: the model was replaced for 'profiles.CustomUser', which was not installed or is abstract.

What could have gone wrong? Thanks in advance.

+6
source share
2 answers

See this answer: Migrating existing auth.User data to a new Django 1.5 custom model?

For others who may experience a similar problem, starting with the user's user model:

If you use "django.contrib.auth" and have a user user model, you cannot run syncdb if your user model is not included in installed applications. You will get this error

CommandError: one or more models were not checked: auth.user: The model was replaced for "myapp.User", which was not installed or is abstract. admin.logentry: "user" refers to the myapp.User model, which either has not been installed or is abstract.

So, to fix this, you need to include the application containing your user model in the installed applications, and now, when you run syncdb, it will add all the tables for your own models. Therefore, you must convert your application to the south, since the tables are already created.

 python manage.py syncdb python manage.py migrate python manage.py convert_to_south myapp 

This will create 0001_initial and you will get this error:

CommandError: one or more models were not checked: auth.user: The model was replaced for 'myapp.User', which was not installed or is abstract.

Workaround:

 python manage.py syncdb python manage.py migrate python manage.py convert_to_south myapp python manage.py migrate myapp 0001 --fake 

You will still get the error above when you run convert_to_south, but now you can ignore it. Southern documentation says:

convert_to_south: South will automatically make and pretend to apply your first migration

I think the problem is that checking the model causes the error_conversion to be converted before it pretends (-fake) to apply the first migration.

So the workaround is to basically do the fake migration that was skipped.

+12
source

I solved the same problem the other day, so I decided that other people might find this useful. This happens when a migration is created before South has compatibility with Django 1.5+. I had a similar problem using the PybbM Forum app on my Django site. The solution is to include your model and its associated models in the ORM of the old migration. There are two ways to do this:

1) You can manually print your model in the "models" list at the bottom of each migration file with an error. 2) Use one of the existing passage migrations as a template and copy the desired orm models to the end.

Example: http://bpaste.net/show/Pv20CM5dTrbubzFZtiRY/

* Keep in mind that you will also need to copy any associated model that the user may need for the user that I made for you, you will need to copy to "ranks.rank", ranks.ranktest 'and' schools. school '

0
source

All Articles