Reputation: 211
I have an application which is using 2 database, 1 is default another is custom. So 2 of my model are using default database, else are using custom database. i do not want to migrate custom database model while running 'make migrations' command. please help it out.
Upvotes: 21
Views: 20065
Reputation: 1
How it worked for me:
managed = False
python manage.py makemigrations
python manage.py migrate
(he writes the creation of tables in the migration file, we ignore it).managed = True
(repeat step 2 and 3)Ps. (This worked when the tables were not in relations, when there was a relation between the tables, it took one more time to do manipulations with managed = True/False)
Upvotes: 0
Reputation: 1190
It's worth mentioning that although the managed
flag is set to False
a migration for the model will still be created but no sql creation script.
The sql of a migration ca be check using manage.py sqlmigrate appname migration
Upvotes: 19
Reputation: 733
Options.managed Defaults to True, meaning Django will create the appropriate database tables in migrate or as part of migrations and remove them as part of a flush management command. That is, Django manages the database tables’ lifecycles.
If False, no database table creation 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. From the docs
class SomeModel(models.Model):
class Meta:
managed = False
Upvotes: 5
Reputation: 1514
You can selectively disable migration for one or more Django-Models by setting managed = False
in Django Model Meta options.
from django.db import models
class LegacyModel(models.Model):
class Meta:
managed = False
Upvotes: 33