Monday, January 27, 2014

Re: migrations to custom user model - complex project

Thanks Arnold, for the details.

Am 25.01.14 21:22, schrieb Arnold Krille:
> We did something similar, we switched from djangos own user model + our
> profile to just using our profile extended by email and password (no
> username anymore and no openid (yet)).
>
> What you need to do depends on whether you can keep the ID's the same
> or not. We couldn't so we had to do the following:
> - In all models that had a foreignkey on the django-user, we added
> another foreignkey on the new user (with default=null).
> - Then we added a data-migration to fill the columns for the new
> user-model with the ids.
> - In the next migration we deactivated all triggers for the
> transaction, removed the constraints for the old django-user
> reference and added constraints for the new user-model.
> - Then the references to the old django-user can be removed. And once
> you defined your user model for django.auth, you have to write your
> own migration to drop the user-model tables from django.auth
> (because south doesn't see that table and model anymore).
> - We also renamed the references to the new user-model to be same as
> the references to the old user-model before all these migrations. So
> most code didn't need changing.
> - Of course you also have to adopt your python code for the
> specialties of the new user model...
>
> If you can keep the IDs the same as before, you probably don't need to
> add a second column for the new model reference. You can 'just' remove
> the constraints from each foreignkey pointing to the old user-model and
> replace it with a constraint pointing to the new user-model. Of course,
> before you do that you need a migration creating your new user-model
> and a data-migration to copy the user-data (most importantly the IDs!)
> to the new tables.
>
> Maybe that helps,
>
> - Arnold

--
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/52E63E2F.3010406%40produktlaunch.de.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment