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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -