{{{
class Decoupe(models.Model):
constante = models.IntegerField()
class Meta:
managed = False
db_table = "Decoupe"
}}}
I ran the first migration and it recognized the options as expected.
Then I removed the meta options, so the model looked like this:
{{{
class Decoupe(models.Model):
constante = models.IntegerField()
}}}
I ran make migrations and it created the following:
{{{
migrations.AlterModelOptions(
name='decoupe',
options={},
),
}}}
When I applied it, nothing really happened and of course, when, trying
from the shell, to to `Decoupe.objects.all()`, I got an error saying that
the table "myapp_decoupe" did not exits.
I would expect either the table to be renamed or at least created empty.
I tried to workaround this replacing the `migrations` above with
{{{
migrations.DeleteModel("decoupe"),
migrations.CreateModel( ... ),
}}}
But when I ran it, I got a error:
`RuntimeError: Error creating new content types. Please make sure
contenttypes is migrated before trying to migrate apps individually.`,
although the contenttypes is migrated.
Is this a bug or desired behavior since the model was "managed=False"?
--
Ticket URL: <https://code.djangoproject.com/ticket/24650>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Sorry, I was in django 1.7.
I also tried removing the "managed=False" from the initial migration and
got the same contenttype error. I did not understand why, since I was not
changing any content type.
I upgraded then to 1.8. The automatically generated migration was the same
and applying it did not change a thing, so I think there is still an
issue. Trying to delete and re-create the model as above raised the same
error.
What did work was removing the "managed=False" from the initial migration.
Django then renamed the table as expected.
Is it intended behavior that any model marked as "managed=False" should
never be changed with django's migration?
--
Ticket URL: <https://code.djangoproject.com/ticket/24650#comment:1>
Comment (by timgraham):
If `managed=False` then you're saying that the table already exists, so I
don't think changing it to `managed=True` should issue a `CREATE TABLE`.
The contenttypes error is probably triggered because the table doesn't
exist. Can you try doing it in two steps: remove `managed=False`, run
`makemigrations`, then remove `db_table` and run `makemigrations`.
--
Ticket URL: <https://code.djangoproject.com/ticket/24650#comment:2>
Comment (by duduklein):
Thanks for your quick response.
Doing it in 2 steps worked in django 1.8 (I did not test in django 1.7).
Regarding the contenttype issue, the table (and the model) did exist. This
issue does not appear in Django 1.8 anymore, so I'm not sure it's worth
digging further.
Maybe it's worth mentioning in the docs that changing a model from the
`managed=False` state to `managed=True` and making other changes should be
done in 2 steps, as you suggested.
Thanks again.
--
Ticket URL: <https://code.djangoproject.com/ticket/24650#comment:3>
* component: Migrations => Documentation
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24650#comment:4>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/7121 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/24650#comment:5>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"80c03b06ad1461c1a07091806dc0414a4e98905e" 80c03b06]:
{{{
#!CommitTicketReference repository=""
revision="80c03b06ad1461c1a07091806dc0414a4e98905e"
Fixed #24650 -- Documented how to change an unmanaged model to managed.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24650#comment:6>
Comment (by Tim Graham <timograham@…>):
In [changeset:"6be255a22a32a58a96b8d1c67485e92b49817b9f" 6be255a2]:
{{{
#!CommitTicketReference repository=""
revision="6be255a22a32a58a96b8d1c67485e92b49817b9f"
[1.10.x] Fixed #24650 -- Documented how to change an unmanaged model to
managed.
Backport of 80c03b06ad1461c1a07091806dc0414a4e98905e from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24650#comment:7>