#24037: Migrating a legacy table results in data loss
-------------------------------+--------------------
Reporter: iambibhas | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I created several models for our legacy database using `inspectdb` and
hence all those models had their `managed` flag set to `False`. Now I need
to make some changes to that model, hence I removed the `managed` flag and
the generated migration wants to drop my table first and then create it
again. Which leads to loss of all my data.
So I edited the migration file and removed the `DeleteModel` operation.
And faked that migration to avoid the error raised by `CreateModel` as the
table already exists.
But now I cannot go backward beyond that migration as the backward
operation of `CreateModel` will drop my table anyway and there is no way
to make a migration irreversible or ask it Not to drop my table.
What would help in such cases is a way to handle the backward migration.
So that I can either choose not to drop my table or raise an exception to
make the migration irreversible. Or at least make the `CreateModel`
operation irreversible. I found that the `Operation` class has a flag
called `reversible`. But I could find no way to set it to `False`.
For now I've added a fake RunPython operation that returns None to make
that migration irreversible, as suggested by Markus
[https://groups.google.com/forum/#!topic/django-users/w9aVT3NOpkM / here].
But I'd love some way to handle it properly.
--
Ticket URL: <https://code.djangoproject.com/ticket/24037>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.6822a7209527d0cce551cba034b931da%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.