django - How to convert many to many field to foreign key? -


lets have model class like;

class samplingquery(models.model):    brands = models.manytomanyfield(brand) 

after while realize need convert manytomanyfield foreignkey need convert class foreignkey;

class samplingquery(models.model):    brands = models.foreignkey(brand) 

is there way without losing data?

thank you

there no simple mechanism, can following:

  1. create new foreignkey (say, brand)

  2. copy existing data brands (by slicing first result since there can multiple manytomany relation) brand

  3. delete field brands


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -