Use foreign key as primary key after merging two models

16 views
Skip to first unread message

scha...@gmail.com

unread,
May 12, 2016, 12:59:57 PM5/12/16
to South Users
HI All,
I'm new in south and I'm wondering how I can merge two models into one.
I have a model book which derives from the model media.
So book has a media_id_ptr (which is already a pk).

No I would like to merge all attributes from media into book and get rid of media.

I was doing the following:

1.) Added all media attributes in the book model, but with _tmp ending.
2.) Created a schemamigration
3.) Created a datamigration and copied the attribute value into the attribute_tmp for all existing book objects.
4.) modified the book model to get rid of the _tmp ending.
5.) Created a schemamigration and exchanged (delete/add with rename column)

But it always fails when I would like to rename the media_id_ptr into id.
I have different m2m tables which used media_id_ptr.
So I guess it is not that easy to reuse the former foreign key as a primary key.

Thanks for any hints how to solve this issue.

Regards
Marcel

Shai Berger

unread,
May 16, 2016, 5:18:28 AM5/16/16
to south...@googlegroups.com
Hi Marcel,

First of all -- just making sure you're aware: South is no longer maintained,
and all the versions of Django that South can work with are also unmaintained.

Second -- for your question -- you need to "move" the m2m's to the Book model.
You may have m2m's in other models referring to Media, and these may cause the
errors you see.

This would perhaps indicate a bug worthy of fixing in South, but no bugs in
South are going to be fixed -- the project is dead; you are strongly encouraged
to update your Django and use Django's migrations.

HTH,
Shai.
Reply all
Reply to author
Forward
0 new messages