Migrating existing auth.User data to new Django 1.5 custom user model?

前端 未结 5 1170
余生分开走
余生分开走 2020-11-30 18:59

I\'d prefer not to destroy all the users on my site. But I want to take advantage of Django 1.5\'s custom pluggable user model. Here\'s my new user model:

         


        
5条回答
  •  时光取名叫无心
    2020-11-30 19:57

    I think you've correctly identified that a migration framework like South is the right way to go here. Assuming you're using South, you should be able to use the Data Migrations functionality to port the old users to your new model.

    Specifically, I would add a forwards method to copy all rows in your user table to the new table. Something along the lines of:

    def forwards(self, orm):
        for user in orm.User.objects.all():
            new_user = SiteUser()
            new_user.save()
    

    You could also use the bulk_create method to speed things up.

提交回复
热议问题