Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29592 closed Bug (duplicate)

Error Migrate When Deleting Empty Model

Reported by: Jauhar Arifin Owned by: Jauhar Arifin
Component: Migrations Version: 2.0
Severity: Normal Keywords: migrations, sqlite
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jauhar Arifin)

Consider we have the following model:

class Animal(models.Model):
    name = models.CharField("Name", max_length=256)
    age = models.IntegerField("Age")

class Cat(Animal):
    pass

class Dog(Animal):
    pass

Lets say, Cat and Dog model don't have fields yet because we don't know yet the requirements. We create migrations first to start working with this simple model. But, someday we realize that Dog model is no longer needed, so we need to delete it. The model became like this:

class Animal(models.Model):
    name = models.CharField("Name", max_length=256)
    age = models.IntegerField("Age")

class Cat(Animal):
    pass

And then, we need to make migrations again. But, after make migrations, I found that there is an error when migrating. The migrations strategy somehow need to rename the table to myapp_dogold, then create new table myapp_dog, and then copy all records in myapp_dogold to myapp_dog. It raise error when using sqlite becase the SQL query looks like this:

INSERT INTO "myapp_dog" () SELECT  FROM "myapp_dog__old"

This happens because dog model has no fields.

Change History (4)

comment:1 by Jauhar Arifin, 6 years ago

Description: modified (diff)

comment:2 by Jauhar Arifin, 6 years ago

Owner: changed from nobody to Jauhar Arifin
Status: newassigned

comment:3 by Jauhar Arifin, 6 years ago

Description: modified (diff)

comment:4 by Simon Charette, 6 years ago

Resolution: duplicate
Status: assignedclosed
Version 0, edited 6 years ago by Simon Charette (next)
Note: See TracTickets for help on using tickets.
Back to Top