Modify

Ticket #675 (assigned defect)

Opened 3 years ago

Last modified 3 years ago

incorrectly deleted primary key

Reported by: dmitriy@… Owned by: andrew
Priority: major Milestone: 1.0
Component: commands Version: unknown
Keywords: Cc:

Description

I have following models (I have simplified)

class Rule(models.Model):
    name = models.CharField(max_length=255)
    advertiser = models.ForeignKey('company.Advertiser')
    campaign = models.ManyToManyField('campaign.Campaign', through='CampaignRule')
    group = models.ForeignKey('RuleGroup', null=True)
        
    class Meta:
        unique_together = ('advertiser', 'name')


class AutoRule(Rule):
    class Meta:
        abstract = True
        

class KeywordRule(AutoRule):
    keyword = models.CharField(max_length=255, blank=False)
    required = models.BooleanField(default=True)
    case_sensitive = models.BooleanField(default=False)

    
class RuleGroup(AutoRule):
    pass

When I first introduced this structure, the generated schema migration added rule_ptr as a primary key to RuleGroup?, but not to KeywordRule?. I added it manually to both the schema migration and to the frozen schema definition in the following data migration, but now every time I do a schema migration, it generates lines to alter KeywordRule? to remove primary key from rule_ptr.

    def forwards(self, orm):
        
        # Changing field 'KeywordRule.rule_ptr'
        db.alter_column('score_keywordrule', 'rule_ptr_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['score.Rule'], unique=True))


    def backwards(self, orm):
        
        # Changing field 'KeywordRule.rule_ptr'
        db.alter_column('score_keywordrule', 'rule_ptr_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['score.Rule'], unique=True, primary_key=True))

Any advice?

Attachments

Change History

comment:1 Changed 3 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.7.3

Hm, that's very strange - one getting the pointer and the other not. I'll have to look into this after I'm back from holiday.

comment:2 Changed 3 years ago by andrew

  • Milestone changed from 0.7.3 to 1.0
View

Add a comment

Modify Ticket

Action
as assigned
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.