﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29592	Error Migrate When Deleting Empty Model	Jauhar Arifin	nobody	"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_dog__old, then create new table myapp_dog, and then copy all records in myapp_dog__old 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. It generates migrations like this:


{{{
operations = [
    migrations.RemoveField(
        model_name='dog',
        name='animal_ptr',
    ),
    migrations.DeleteModel(
        name='Dog',
    ),
]
}}}

But, it should be just like this:

{{{
operations = [
    migrations.DeleteModel(
        name='Dog',
    ),
]
}}}

"	Bug	new	Migrations	2.0	Normal		migrations, sqlite		Unreviewed	0	0	0	0	0	0
