makemigrations running for all apps defined in INSTALLED_APPS

1,252 views
Skip to first unread message

Priyanka Thakur

unread,
Jun 6, 2017, 6:52:00 AM6/6/17
to Django users
Hi,

I am migrating from Django 1.7.4 to  Django 1.10.0 and is facing issue while running migrations.

I am running the comand : python manage.py makemigrations <app_name>

Scenario, is that we araccessing model from Oracle database, for which I don't have read/write permissions and i had to change the model definition in local source to add related_name .

I want to skip/exclude this model while running makemigrations, but is not able to do so.

I tried returning "False" in the router, but that also is not working.

Please suggest solution/workaround. Also, please feel free to correct me , if I'm wrong.

Data :


Model :

With Django 1.7:

class PartVersionTree(models.Model):

fk_partversion = models.ForeignKey(PartVersion, null=True, blank=True,db_column='FK_PARTVERSION')

fk_associatedpartversion = models.ForeignKey(PartVersion, null=True, blank=True,db_column='FK_ASSOCIATEDPARTVERSION')


Changed in Django 1.10:

class PartVersionTree(models.Model):
fk_partversion = models.ForeignKey(PartVersion, null=True, blank=True,db_column='FK_PARTVERSION', related_name = '%(class)s_fk_partversion')
    fk_associatedpartversion = models.ForeignKey(PartVersion, null=True, blank=True,db_column='FK_ASSOCIATEDPARTVERSION', related_name = '%(class)s_fk_associatedpartversion')



Router definition:

    def allow_migrate(self, db, app_label, model_name=None, **hints):

        return False


Regards,
Priyanka

Daniel Roseman

unread,
Jun 6, 2017, 9:54:56 AM6/6/17
to Django users
Add `managed = False` to the model's inner Meta class.

--
DR. 

devansh dixit

unread,
Jun 6, 2017, 12:55:09 PM6/6/17
to Django users
just run >>>   python manage.py migrations this will help
you 

Melvyn Sopacua

unread,
Jun 6, 2017, 1:20:25 PM6/6/17
to django...@googlegroups.com

On Tuesday 06 June 2017 05:45:32 devansh dixit wrote:

> > just run >>> python manage.py migrations this will help

>

> you

 

No, it won't.

First it's `makemigrations`, second, he doesn't want to migrate the model, just the code.

It's an unmanaged model, so the correct fix, as Daniel pointed out is to declare the model as such.

 

And to clarify, why returning false in the router doesn't help:

The router check is one of 3 checks done. If any of the checks return True, it will attempt to make a migration.

--

Melvyn Sopacua

Priyanka Thakur

unread,
Jun 7, 2017, 5:43:47 AM6/7/17
to Django users
Nothing helps till now !!

Thanks,
Priyanka

Melvyn Sopacua

unread,
Jun 7, 2017, 7:16:56 AM6/7/17
to django...@googlegroups.com

On Tuesday 06 June 2017 22:43:46 Priyanka Thakur wrote:

> Nothing helps till now !!

 

I'm going to guess, that marking a managed model as unmanaged, is a migration that needs to be done to keep a consistent migration history.

 

So first, make only that change and make the migration for it. Then change the related name and it should no longer make a migration.

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages