{{{
django-admin startproject sample
cd sample
python manage.py startapp unmanaged
echo 'from django.db import models
class ForeignUnmanagedTable(models.Model):
rowid = models.AutoField(primary_key=True)
class Meta:
managed = False
db_table = "foreign_unmanaged_table"
' > unmanaged/models.py
sed -i '/.*django.contrib.staticfiles.*/a
"unmanaged.apps.UnmanagedConfig", ' sample/settings.py
python manage.py makemigrations
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33168>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Comment:
Unmanaged models are tracked in migrations but database operations for
unmanaged models aren't performed.
--
Ticket URL: <https://code.djangoproject.com/ticket/33168#comment:1>
Comment (by Javier Domingo Cansino):
I'm not sure if I understand your mesage, but bisecting the problem, it
seems like a change in behaviour between python2 and python3.
Just in case, the problem is that given a model with managed=False,
makemigrations generate migrations for that model. This behaviour is
documented in [1] however it is only respected when running python 2 with
older versions of Django.
[1] https://docs.djangoproject.com/en/3.2/ref/models/options/#managed
--
Ticket URL: <https://code.djangoproject.com/ticket/33168#comment:2>
Comment (by Tim Graham):
Migrations should be generated for unmanaged models (to track their
state), however, running the migration should have no effect on the
database.
--
Ticket URL: <https://code.djangoproject.com/ticket/33168#comment:3>
* status: closed => new
* resolution: invalid =>
Comment:
I have opened https://github.com/django/django/pull/14934 to clarify this
in the documentation
--
Ticket URL: <https://code.djangoproject.com/ticket/33168#comment:4>
* type: Bug => Uncategorized
* component: Migrations => Documentation
--
Ticket URL: <https://code.djangoproject.com/ticket/33168#comment:5>
* status: new => closed
* type: Uncategorized => Cleanup/optimization
* resolution: => wontfix
Comment:
I appreciate you'd like to reopen the ticket, however I don't think that
an extra clarification is needed. It's already documented that:
> ''If False, **no database table creation, modification, or deletion
operations will be performed** for this model. This is useful if the model
represents an existing table or a database view that has been created by
some other means. **This is the only difference when managed=False. All
other aspects of model handling are exactly the same as normal.**''
We cannot document here all aspects of model handling.
--
Ticket URL: <https://code.djangoproject.com/ticket/33168#comment:6>