[SEBA-500] Always generate core models before a migration as service models depend on them

Change-Id: I0f007f9f3d217703869847d6cf570093c7af6363
diff --git a/VERSION b/VERSION
index 5472708..fdacbdb 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.1.56
+2.1.57
diff --git a/containers/chameleon/Dockerfile.chameleon b/containers/chameleon/Dockerfile.chameleon
index 5df913a..9079966 100644
--- a/containers/chameleon/Dockerfile.chameleon
+++ b/containers/chameleon/Dockerfile.chameleon
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 # xosproject/chameleon
-FROM xosproject/xos-base:2.1.56
+FROM xosproject/xos-base:2.1.57
 
 # xos-base already has protoc and dependencies installed
 
diff --git a/containers/xos/Dockerfile.client b/containers/xos/Dockerfile.client
index 6d92bb6..e69843c 100644
--- a/containers/xos/Dockerfile.client
+++ b/containers/xos/Dockerfile.client
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 # xosproject/xos-client
-FROM xosproject/xos-libraries:2.1.56
+FROM xosproject/xos-libraries:2.1.57
 
 
 # Install XOS client
diff --git a/containers/xos/Dockerfile.libraries b/containers/xos/Dockerfile.libraries
index 987c196..5432413 100644
--- a/containers/xos/Dockerfile.libraries
+++ b/containers/xos/Dockerfile.libraries
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 # xosproject/xos-libraries
-FROM xosproject/xos-base:2.1.56
+FROM xosproject/xos-base:2.1.57
 
 # Add libraries
 COPY lib /opt/xos/lib
diff --git a/containers/xos/Dockerfile.synchronizer-base b/containers/xos/Dockerfile.synchronizer-base
index 1aded9f..e5c6aca 100644
--- a/containers/xos/Dockerfile.synchronizer-base
+++ b/containers/xos/Dockerfile.synchronizer-base
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 # xosproject/xos-synchronizer-base
-FROM xosproject/xos-client:2.1.56
+FROM xosproject/xos-client:2.1.57
 
 COPY xos/synchronizers/new_base /opt/xos/synchronizers/new_base
 COPY xos/xos/logger.py /opt/xos/xos/logger.py
diff --git a/containers/xos/Dockerfile.xos-core b/containers/xos/Dockerfile.xos-core
index c62d2fe..c3ef7c7 100644
--- a/containers/xos/Dockerfile.xos-core
+++ b/containers/xos/Dockerfile.xos-core
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 # xosproject/xos-core
-FROM xosproject/xos-libraries:2.1.56
+FROM xosproject/xos-libraries:2.1.57
 
 # Install XOS
 ADD xos /opt/xos
diff --git a/lib/xos-migrate/xosmigrate/main.py b/lib/xos-migrate/xosmigrate/main.py
index 312477d..3bea379 100644
--- a/lib/xos-migrate/xosmigrate/main.py
+++ b/lib/xos-migrate/xosmigrate/main.py
@@ -311,6 +311,9 @@
 
 
 def run():
+    # cleaning up from possible incorrect states
+    if "INSTALLED_APPS" in os.environ:
+        del os.environ["INSTALLED_APPS"]
 
     args = parser.parse_args()
 
@@ -336,9 +339,9 @@
     # generate the code for each service and create a list of parameters to pass to django
     app_list = []
     for service in args.service_names:
+        # NOTE we need core models to be there as all the services depend on them
+        generate_core_models(core_dir)
         if service == "core":
-
-            generate_core_models(core_dir)
             django_cli_args.append("core")
         else:
             service_dir = os.path.join(service_base_dir, service)
@@ -348,7 +351,8 @@
 
             django_cli_args.append(service_name)
 
-    os.environ["INSTALLED_APPS"] = ",".join(app_list)
+    if len(app_list) > 0:
+        os.environ["INSTALLED_APPS"] = ",".join(app_list)
 
     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")