Django: exclude models from migrations

In my django application (django 1.8), I use two databases, one " default ", which is MySQL, and the other, which is a read-only schema. I have two models that access this database, and I would like to exclude these two models permanently from data and schema migration:

  • makemigrations should never detect any changes and create migrations for them
  • migrate should never complain about the lack of migration for this application.

So far I have tried different things, all without success:

  • used the option managed=False Meta on both models
  • allow_migrate method is allow_migrate for my router, which returns False for both models

Does anyone have an example of how this scenario can be achieved? Thank you for your help!

+8
python django django-models django-migrations
source share
2 answers

So far I have tried different things, all without success:

  • used the managed = False Meta parameter for both models

This option (the managed = False attribute in the model metafiles) seems to meet the requirements.

If not, you will need to expand the question to say for sure what is special about your model that managed = False does not do the job.

+1
source share

I thought I had a problem with makemigrations. It claims to migrate according to the managed = False model, but no SQL code has been created for this model

Here is my example, the Smdocumets model Smdocumets unmanaged, and the SQL code was not 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"; ... 
0
source share

All Articles