Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable migration from one model of an app in django

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.

like image 630
nidhi Avatar asked Nov 20 '15 06:11

nidhi


People also ask

How do I stop migrations in Django?

Using --no-migrations (alias: --nomigrations ) will disable Django migrations and create the database by inspecting all models.

How do I delete a specific migration in Django?

There is a solution: run migrations 2 and 3 backwards with ./manage.py migrate my_app 0001 , then delete migration files. If you can't migrate back (e.g. you messed up with your database manually) then you can fake migrate back with ./manage.py migrate my_app 0001 --fake and set up database as it should be manually.


1 Answers

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
like image 59
elim Avatar answered Sep 21 '22 18:09

elim