Monday, February 18, 2013

Re: Migrating existing auth.User users to Django 1.5 Custom User table

On Mon, Feb 18, 2013 at 4:33 PM, Ben Roberts <ben@nutrislice.com> wrote:
> I assume, when Django 1.5 hits the public in 2014 >;) that many will want to
> take advantage of some facet of the new pluggable User models. You may,
> like me, want to add an additional column (field) or two in your custom
> User.
>
> E.g.:
>
> class SiteUser(AbstractUser):
> site = models.ForeignKey(Site, null=True)
>
>
> However, you have an exiting table of users and need to migrate them to your
> new model/table. How? My current challenge is that I don't see any clear,
> scriptable way to do this, whether it be through South, SQL, or
> dumpdata/loaddata.
>
> Have an answer that's more than just a fleeting suggestion? Feel free to
> grab the bounty on the Stack Overflow question if your answer works, or
> respond here if SO isn't your thing.
>

South migrations do not have to be automatically generated, there is a
rich API for making schema altering migrations:

http://south.readthedocs.org/en/latest/databaseapi.html#db-rename-table

Therefore, it simply comes down to what steps are required. Something
like this should suffice:

Add 'custom' user model that has exactly the same fields as the
current user model.
Add a schema migration to rename auth_user to the new required table name
Run your migration
Modify the user model as you see fit
Generate schema migrations as per any other model

Cheers

Tom

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate