Django makemigrations is creating migrations for model with managed = False

Viewed 1820

While Django documentation https://docs.djangoproject.com/en/3.1/ref/models/options/#managed mentions the use of managed = False field in meta is used to not create migrations

I am still getting migrations when I call makemigrations.

This is the meta of the model:

class FieldOpsBooking(models.Model):
    .
    .
    class Meta:
        managed = False
        db_table = 'field_ops_booking'

And I am getting this after makemigrations python manage.py makemigrations

Migrations for 'user_analysis':
  user_analysis/migrations/0001_initial.py
    - Create model FieldOpsBooking
    - Create model RewardManagementLeads
Migrations for 'od_engagement':
  od_engagement/migrations/0001_initial.py
    - Create model NormalisedTonnage

And it creates 0001_initial.py file with all migrations to apply as well.

Any help is appreciated

2 Answers

I checked my own projetcs with models having managed=False: YES there is an entry in migrations file like:

    operations = [
        migrations.CreateModel(
            name='xyz',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ],
            options={
                'db_table': 'xyz_table',
                'managed': False,
            },
        ),

BUT: this will not create a new table on database level when you execute "makemigration". Sorry if a insiste but your original solution was absolutely correct!!

this is from django documentation about abtract base class: " ... since it is an abstract base class. .... and cannot be instantiated or saved directly."

You can set abstract=True in Meta to prevent model from migration as follows:

class FieldOpsBooking(models.Model):
   .....
   class Meta:
       abstract = True
   ..... 
Related