Can migrated apps depend on unmigrated apps?

143 views
Skip to first unread message

Carsten Fuchs

unread,
Feb 4, 2015, 12:27:03 PM2/4/15
to django...@googlegroups.com
Dear Django developers,

can apps that use migrations depend on unmigrated apps?

The documentation at
<https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies>
explains how dependencies work, and explicitly mentions that unmigrated
apps cannot depend on migrated apps.

In turn it seems to imply that migrated apps *can* depend on unmigrated
apps, but is that correct? In the docs example where `books` have a
foreign key and thus depend on `authors`, does it really work if
`authors` is unmigrated? How would it be able to run the `authors`
migration to create the table the foreign key in `books` references, if
`authors` is unmigrated?


This is an implication of my so far unfruitful attempts to add
migrations to an older, existing app as described in thread
<https://groups.google.com/forum/#!topic/django-users/lVS24BGFouo>,
where I have exactly this situation:

The older app is still unmigrated (as I could not yet find a way to
overcome the problems with making it migrated), and would like to create
a new one in the meanwhile. The new app has a foreign key on a model in
the old one, and now I'm wondering if it is wise to proceed...?

Any hints and help would very much be appreciated! :-)

Best regards,
Carsten

Carsten Fuchs

unread,
Feb 17, 2015, 3:31:15 PM2/17/15
to django...@googlegroups.com
Hi all,

Am 04.02.2015 um 18:26 schrieb Carsten Fuchs:
> can apps that use migrations depend on unmigrated apps?

Anyone please?

It seems like this works in practice, but this still looks like a
contradiction to me, and I would still be interested in some feedback
for a firmer foundation for ongoing work…

Best regards,
Carsten

Michael Pöhn

unread,
Feb 17, 2015, 4:45:23 PM2/17/15
to django...@googlegroups.com
This is all covered in Djangos documentation...
https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies

Let me paste the relevant parts for you:

»Be aware, however, that unmigrated apps cannot depend on migrated apps,
by the very nature of not having migrations. This means that it is not
generally possible to have an unmigrated app have a ForeignKey or
ManyToManyField to a migrated app; some cases may work, but it will
eventually fail.

Warning: Even if things appear to work with unmigrated apps depending on
migrated apps, Django may not generate all the necessary foreign key
constraints.«

br.
Michael

Carsten Fuchs

unread,
Feb 17, 2015, 5:00:26 PM2/17/15
to django...@googlegroups.com
Hi Michael,

Am 17.02.2015 um 22:44 schrieb Michael Pöhn:
> This is all covered in Djangos documentation...
> https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies

Well, no... please see below.

> Let me paste the relevant parts for you:
>
> »Be aware, however, that unmigrated apps cannot depend on migrated apps, [...]«

This explains that unmigrated apps cannot depend on migrated apps.

My question is about the opposite case: Can migrated apps depend on
unmigrated apps? I've explained the apparent problem in greater detail
in my original post.

Best regards,
Carsten

Collin Anderson

unread,
Feb 19, 2015, 1:35:18 PM2/19/15
to django...@googlegroups.com
Hi Carsten,

I in my experience, it _sometimes_ works to have migrated apps depend on unmigrated apps.

If you haven't yet, you could try generating migrations for the unmigrated app, and reference them using MIGRATION_MODULES.

Collin

Carsten Fuchs

unread,
Feb 20, 2015, 9:37:15 AM2/20/15
to django...@googlegroups.com
Hi Collin,

thank you very much for your reply!

Am 19.02.2015 um 19:35 schrieb Collin Anderson:
> If you haven't yet, you could try generating migrations for the
> unmigrated app, and reference them using MIGRATION_MODULES.

I've tried this, and my real problem is that I have problems with this
step, i.e. applying the initial migrations to the unmigrated app: Please
see <https://groups.google.com/forum/#!topic/django-users/lVS24BGFouo>
for details. Any help about this would very much be appreciated!

Many thanks and best regards,
Carsten

Reply all
Reply to author
Forward
0 new messages