title: Django: ForeignKey and related_name
body: <p>Please help me to write model with ForeignKeys.</p>
  
  <p>Table 1:</p>
  
  <pre><code>| ports | CREATE TABLE `ports` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `device_id` int(11) DEFAULT NULL,
  `name` int(10) DEFAULT NULL,
  `login` varchar(255) DEFAULT NULL,
  `state` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `device_id` (`device_id`),
  KEY `name` (`name`),
  KEY `state` (`state`),
  KEY `login` (`login`),
  CONSTRAINT `ports_ibfk_1` FOREIGN KEY (`device_id`) REFERENCES 
  `switch` (`id`) ON DELETE CASCADE
  )
  </code></pre>
  
  <p>Model for table 1:</p>
  
  <pre><code>class Ports(models.Model):
      device_id = models.ForeignKey('Switch', models.DO_NOTHING, blank=True, null=True)
      name = models.IntegerField(blank=True, null=True)
      login = models.CharField(max_length=255, blank=True, null=True)
      state = models.IntegerField(blank=True, null=True)
  
      class Meta:
          managed = False
          db_table = 'ports'
  </code></pre>
  
  <p>Table 2:</p>
  
  <pre><code>| switch | CREATE TABLE `switch` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL DEFAULT '',
  `addr` varchar(255) NOT NULL DEFAULT '',
  `community` varchar(255) NOT NULL DEFAULT '',
  `type` int(11) DEFAULT NULL,
  `ports` int(11) DEFAULT NULL,
  `street_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `type` (`type`),
  CONSTRAINT `switch_ibfk_1` FOREIGN KEY (`type`) REFERENCES `switch_types` (`id`)
  ) 
  </code></pre>
  
  <p>Model for table 2:</p>
  
  <pre><code>class Switch(models.Model):
      name = models.CharField(max_length=255)
      addr = models.CharField(max_length=255)
      community = models.CharField(max_length=255)
      type = models.ForeignKey('SwitchTypes', models.DO_NOTHING, db_column='type', blank=True, null=True)
      ports = models.IntegerField(blank=True, null=True)
      street_id = models.IntegerField(blank=True, null=True)
  
      class Meta:
          managed = False
          db_table = 'switch'
  </code></pre>
  
  <p>When i run the server i get an error:</p>
  
  <blockquote>
    <p>ERRORS:</p>
    
    <p>api.Ports.device_id: (fields.E303) Reverse query name for 'Ports.device_id' clashes with field name 'Switch.ports'.
        HINT: Rename field 'Switch.ports', or add/change a related_name argument to the definition for field 'Ports.device_id'.</p>
  </blockquote>
  
  <p>I can not rename ports column in the Switch table in MySQL. Read-only.
  What related_name of device_id field I should set? If I add related_name='+' all works without errors, but '+' disables mapping. 
  Or I need to do something else?</p>