Django Migrations - How To Make It Forget?
I've been sketching out a new Django app with the runserver dev server running in a background window to tracking network wiring, and briefly had this in my model: class Interface(
Solution 1:
In case you don't need a backwards relation add related_name='+'
to your field definition. From the doc:
user = models.ForeignKey(User, related_name='+')
Solution 2:
In your first example:
classConnection(models.Model):
interface_from = models.ForeignKey(Interface, related_name="connections")
interface_to = models.ForeignKey(Interface, related_name="connections")
You're telling Django to create two different connections
attributes on Interface
for the backwards relationships back to Connection
, which obviously doesn't work.
In your second example:
classConnection(models.Model):
interface_from = models.ForeignKey(Interface)
interface_to = models.ForeignKey(Interface)
You're telling Django to use its default connections_set
name for two different attributes for the backwards relationships back to Connection
, which also doesn't work.
The fix is to use related_name='+'
(as @Ivan said) to disable the backwards relationships completely or two explicitly provide two different related_name
attributes so that the backwards relationship attributes' names don't clash.
Post a Comment for "Django Migrations - How To Make It Forget?"