Modify

Ticket #150 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

Wrong order of tables for deletion in forwards() in case of ManyToMany migration

Reported by: Sergey Belov <peimei@…> Owned by: andrew
Priority: major Milestone: 0.7
Component: migrations Version: 0.6-pre
Keywords: Cc:

Description

Example migration:

class Migration:

    def forwards(self, orm):
        # Adding model 'JiraTicket'
        db.create_table('tickets_jiraticket', (
            ('id', models.AutoField(primary_key=True)),
            ('key', models.CharField(unique=True, max_length=64, db_index=True)),
        ))
        db.send_create_signal('tickets', ['JiraTicket'])
        
        # Adding ManyToManyField 'Ticket.jira_tickets'
        db.create_table('tickets_ticket_jira_tickets', (
            ('id', models.AutoField(primary_key=True, auto_created=True)),
            ('ticket', models.ForeignKey(orm.Ticket, null=False)),
            ('jiraticket', models.ForeignKey(orm.JiraTicket, null=False))
        ))


    def backwards(self, orm):
        db.delete_table('tickets_jiraticket')
        db.delete_table('tickets_ticket_jira_tickets')

Should be:

class Migration:

    def forwards(self, orm):
        # Adding model 'JiraTicket'
        db.create_table('tickets_jiraticket', (
            ('id', models.AutoField(primary_key=True)),
            ('key', models.CharField(unique=True, max_length=64, db_index=True)),
        ))
        db.send_create_signal('tickets', ['JiraTicket'])
        
        # Adding ManyToManyField 'Ticket.jira_tickets'
        db.create_table('tickets_ticket_jira_tickets', (
            ('id', models.AutoField(primary_key=True, auto_created=True)),
            ('ticket', models.ForeignKey(orm.Ticket, null=False)),
            ('jiraticket', models.ForeignKey(orm.JiraTicket, null=False))
        ))


    def backwards(self, orm):
        db.delete_table('tickets_ticket_jira_tickets')
        db.delete_table('tickets_jiraticket')

It is critical for MySQL.

Attachments

Change History

comment:1 Changed 5 years ago by andrew

  • Status changed from new to assigned

comment:2 Changed 5 years ago by andrew

See also #94

comment:3 Changed 5 years ago by andrew

  • Milestone changed from 0.6 to 0.7

Bumping to 0.7, is a bigger change.

comment:4 Changed 4 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed

This is fixed, but not by fixing the ordering; MySQL's foreignkey checks are now turned off during deletion, so it won't complain.

View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.