Add new primary key to model

17 views
Skip to first unread message

Joakim Hove

unread,
Feb 18, 2017, 8:36:14 AM2/18/17
to Django users
Hello;

I have a model with a CharField which is used as primary key:

    class MyModel( Model ):
             string_id = CharField("StringID" , primary_key = True )

I would now like to migrate this model to have a normal integer AutoField as primary key, and the string_id field should just be a unique string:


    class MyModel( Model ):
           int_id = AutoField( primary_key = True )
           string_id = CharField( "StringID", unique = True )


I have tried several ways of doing this, but it either fails in the 'makemigrations' step, or when I try to apply the migration. Any tips?

Joakim
Reply all
Reply to author
Forward
0 new messages