[Fixed]-Django: exclude models from migrations

2👍

So far, I’ve tried different things, all without any success:

  • used the managed=False Meta option on both Models

That option (the managed = False attribute on the model’s meta options) seems to meet the requirements.

If not, you’ll need to expand the question to say exactly what is special about your model that managed = False doesn’t do the job.

2👍

I thought, I have a problem with makemigrations. It pretends to make migration on managed = False model, but no SQL code generated for this model

Here is my example, model Smdocumets unmanaged, and no SQL code was generated.

python manage.py makemigrations

Migrations for 'monitor':
  monitor\migrations\0005_auto_20171102_1125.py
    - Create model Smdocuments
    - Add field sid to db
    - Alter field name on db

python manage.py sqlmigrate monitor 0005

BEGIN;
--
-- Create model Smdocuments
--
--
-- Add field sid to db
--
ALTER TABLE "monitor_db" RENAME TO "monitor_db__old"; 
...
👤Lamak

2👍

You have the correct solution:

used the managed=False Meta option on both Models

It may appear that it is not working but it is likely that you are incorrectly preempting the final result when you see - Create model xxx for models with managed = False when running makemigrations.
How have you been checking/confirming that migrations are being made?

makemigrations will still print to terminal - Create model xxx and create code in the migration file but those migrations will not actually result in any SQL code or appear in Running migrations: when you run migrate.

👤Ron

Leave a comment