Renaming a foreign key field with a different related_name, too

330 views
Skip to first unread message

bobhaugen

unread,
Apr 24, 2014, 7:34:35 PM4/24/14
to south...@googlegroups.com
I have renamed fields in South migrations several times when I wanted to retain the data (changing the add and delete fields to rename_column).  Always worked fine.

But now I am renaming a foreign key field for the first time, and also changing the related name, and am confused. (And ran a test, which failed.)

I notice that when South creates an auto migration which adds a foreign key field, it also adds information about the related name, for example (from a previous migration):
    self.gf('django.db.models.fields.related.ForeignKey')(default=1, related_name='cached_events', to=orm['valueaccounting.EventType']),

So what do I need to do when renaming both the foreign key field and the related name?

Do the rename_column differently?

Do the rename_column first and then change the related name in a separate migration?

Can't do it at all?

Or what?

Thanks a bunch, we love South and are glad it is becoming part of Django (in a version beyond our current one...)

Andrew Godwin

unread,
Apr 25, 2014, 5:05:08 AM4/25/14
to south...@googlegroups.com
related_name has no effect on the database, so there should be no problem changing it.

Are you actually seeing any errors? If so, could you post the traceback + console output of them?

Andrew


--
You received this message because you are subscribed to the Google Groups "South Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to south-users...@googlegroups.com.
To post to this group, send email to south...@googlegroups.com.
Visit this group at http://groups.google.com/group/south-users.
For more options, visit https://groups.google.com/d/optout.

Bob Haugen

unread,
Apr 25, 2014, 6:36:15 AM4/25/14
to south...@googlegroups.com
Andrew, thanks. That's the info I needed (that South does not need the
new related name). Led me to dig deeper and find a leftover remnant of
the old field name in a place I did not expect. (As always.)

Sorry to bother you and the group.
> You received this message because you are subscribed to a topic in the
> Google Groups "South Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/south-users/Lrnn2uPfr50/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
Reply all
Reply to author
Forward
0 new messages