elpaso / django-dag

Basic portable Directed Acyclic Graph application for Django
65 stars 19 forks source link

Problems with migrations in Django 1.11 #24

Open math-a3k opened 6 years ago

math-a3k commented 6 years ago

I'm developing a package with Django 1.11 which depends on django-dag.

There are 2 models in the app depending on dag:

class BayesianNetworkEdge(
        edge_factory('bayesian_networks.BayesianNetworkNode')):
        ....

class BayesianNetworkNode(
        node_factory('bayesian_networks.BayesianNetworkEdge')):
        ....

The problem is that on a fresh install, django_dag does not ships with the initial migration and Django creates it when another migration requiring it is created.

If I ship that migration (pointing to django_dag tables) it will fail on a fresh install because it points to a non-existent one, and the migrations have to be deleted and recreated to trigger the creation of dag tables.

Have you consider including an initial migration with those tables in order to fix this kind of problems?

math-a3k commented 6 years ago

https://github.com/math-a3k/django-ai

math-a3k commented 6 years ago

This migration does the trick: https://github.com/math-a3k/django-ai/blob/master/misc/django_dag_0001_initial.py Though not without caveats, it will ask for a default value for the existing rows - which are none, because is an initial, so you can safely put any number.

I still can't find where the problem is exactly, if django_ai is installed as a package, Django creates the migrations "well", but inside the package it doesn't: it creates either django_dag's or the django_ai's app, pointing to each other and ending up in a circular dependency error.

The solution is copying that migration to django_dag migrations and migrate your app, that way it will go smoothly (with the "default value" caveat)