[Django] #29592: Error Migrate When Deleting Empty Model

2 views
Skip to first unread message

Django

unread,
Jul 24, 2018, 6:55:44 PM7/24/18
to django-...@googlegroups.com
#29592: Error Migrate When Deleting Empty Model
-------------------------------------+-------------------------------------
Reporter: Jauhar | Owner: nobody
Arifin |
Type: Bug | Status: new
Component: | Version: 2.0
Migrations |
Severity: Normal | Keywords: migrations, sqlite
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29592>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 24, 2018, 7:04:05 PM7/24/18
to django-...@googlegroups.com
#29592: Error Migrate When Deleting Empty Model
------------------------------------+--------------------------------------
Reporter: Jauhar Arifin | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: migrations, sqlite | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Description changed by Jauhar Arifin:

Old description:

> 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.

New description:

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',
),
]
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29592#comment:1>

Django

unread,
Jul 24, 2018, 7:06:14 PM7/24/18
to django-...@googlegroups.com
#29592: Error Migrate When Deleting Empty Model
-------------------------------------+-------------------------------------
Reporter: Jauhar Arifin | Owner: Jauhar
| Arifin
Type: Bug | Status: assigned

Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: migrations, sqlite | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jauhar Arifin):

* status: new => assigned
* owner: nobody => Jauhar Arifin


--
Ticket URL: <https://code.djangoproject.com/ticket/29592#comment:2>

Django

unread,
Jul 24, 2018, 8:00:14 PM7/24/18
to django-...@googlegroups.com
#29592: Error Migrate When Deleting Empty Model
-------------------------------------+-------------------------------------
Reporter: Jauhar Arifin | Owner: Jauhar
| Arifin
Type: Bug | Status: assigned
Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: migrations, sqlite | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Jauhar Arifin:

Old description:

> 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',
> ),
> ]
> }}}

New description:

class Cat(Animal):
pass

class Dog(Animal):
pass

}}}

class Cat(Animal):
pass
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29592#comment:3>

Django

unread,
Jul 24, 2018, 11:04:12 PM7/24/18
to django-...@googlegroups.com
#29592: Error Migrate When Deleting Empty Model
-------------------------------------+-------------------------------------
Reporter: Jauhar Arifin | Owner: Jauhar
| Arifin
Type: Bug | Status: closed
Component: Migrations | Version: 2.0
Severity: Normal | Resolution: duplicate

Keywords: migrations, sqlite | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: assigned => closed
* resolution: => duplicate


Comment:

Duplicate of #24424.

See https://code.djangoproject.com/ticket/24424#comment:23

--
Ticket URL: <https://code.djangoproject.com/ticket/29592#comment:4>

Reply all
Reply to author
Forward
0 new messages