In my django application (django 1.8) I'm using two databases, one 'default
' which is MySQL, and another one which is a schemaless, read-only database.
I've two models which are accessing this database, and I'd like to exclude these two models permanently from data and schema migrations:
makemigrations
should never detect any changes, and create migrations for themmigrate
should never complain about missing migrations for that appSo far, I've tried different things, all without any success:
managed=False
Meta option on both Modelsallow_migrate
method to my router which returns False
for both modelsDoes anyone have an example of how this scenario can be achieved? Thanks for your help!
migrate , which is responsible for applying and unapplying migrations. makemigrations , which is responsible for creating new migrations based on the changes you have made to your models.
You can selectively disable migration for one or more Django-Models by setting managed = False in Django Model Meta options. Save this answer.
Using django 2.1, this works for me: /manage.py migrate my_app 0010 , only 0010 , not the full file name. After that, manually delete the local files appname/migrations/0011+, then manually delete row(s) from django_migrations db table for 0011+.
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.
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";
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With