Why does "makemigrations" work but "migrations" command said "No migrations to apply"?

Good day! I will try to explain this problem in much detail as I can.

I have built a django app (in this case it is named Partners App) and configured its models.py and admin.py files. It seems to be working since in my openedx tutor instance, the models I’ve created reflects in the admin side of my website as you can see in the image below.

image

But whenever I click on it, it returns a 500 error. I checked the log files and that’s when I found out that the tables were not even created in the database. It just reflects in the admin side and I don’t know why. I tried searching for a fix and I’ve applied everything that I’ve searched for.

For example, when I am running the tutor local quickstart command, it is to be expected that the migrations should take effect, but it doesn’t detect the partners app’s models.py automatically.

Some of you might ask, " Did you check if it is in the INSTALLED_APPS?" well, the answer is yes. My django app is detected by the openedx instance. But why would the app be detected but its models.py can’t be detected?

To explain the problem further, a suggestion from a research has explained that I should specify the app if I were to create tables via migrations, so that’s what I did. I tried to run tutor local run lms ./manage.py lms makemigrations partners and here’s what happened:

Migrations for ‘partners’:
/openedx/requirements/partners-page/partners/migrations/0001_initial.py
- Create model Expert
- Create model Partner
- Create model PartnerCourse
- Add field partner to expert

With this, I suspect that the makemigrations command worked successfully. So I tried running the next command to create my tables which is tutor local run lms ./manage.py lms migrate partners, but here’s when the error popped out where I can’t find any fixes yet and can’t progress any further.

Despite that the makemigration worked, I don’t know why the migrate command didn’t. By this time, none on the internet helped me so far. I would be waiting for answers and guidance from the experts.

For more details regarding my problem, the django app I’ve created was built through the cookiecutter-django-app.

Then, upon performing the migrate command, one of the errors indicated that the app:

“Partners does not have migrations”.

Upon searching for fixes, I’ve found out that a migration folder with an __init__.py should be detected inside my app before openedx can detect the app’s models.py. So I created that directory, but then, by that, the above error in this whole post occured and now I’m stuck.

Also upon performing makemigration command several times, I’ve noticed that the 0001_initial.py file does not even increment (Refer to image below).
image

I’m not quite sure if it could help but I hope it’s enough to explain my problem.

I found the solution! But I hope someone could explain this to me. If it’s clear, I’d consider that the solution instead of this:

The command tutor local run lms ./manage.py lms makemigrations partners works successfully on my end but the command tutor local run lms ./manage.py lms migrate partners doesn’t. So I tried:

tutor local run lms ./manage.py lms migrate --run-syncdb

and it works! My tables have been created.

But sadly, tutor local quickstart does not include my django app in making migrations and migrating. Also, the error is still there even there are generated tables already, and even though the local quickstart completed successfully. Such as the image below:

image

Why is that?
Why can’t openedx detect the tables of my partners app automatically?
If I would add another django app, should I migrate them manually all the time via tutor local run lms ./manage.py lms makemigrations <app_name> or should I only do this the first time?
Also if there is a way for openedx to detect it automatically, how?

I have a lot of questions since I don’t know how this command fixed it though. I would still be waiting for experts.

I think the problem is how you’ve installed the django app.

It sounds to me like what’s happening is this:

  1. When you run ./manage.py lms makemigrations partners, Tutor spins up a temporary LMS container, and within that container it generates /openedx/requirements/partners-page/partners/migrations/0001_initial.py
  2. But as soon as the command finishes, that container is terminated, and the changes (to Partners App code) are not saved anywhere.
  3. When you run the migrate command, it runs in a brand new container which won’t have 0001_initial.py, so it displays the error.

If you bind mount your partners app into Tutor, you will avoid this problem. With a bind mount setup, as soon as you run makemigrations, you’ll see the 0001_initial.py appears in the source folder on your host computer, where you have the code. It will now live “permanently” in that folder on your host computer, as opposed to being a temporary file in the container. With this setup, you can also make changes to the app code and see them reflected immediately within the LMS (after it auto-reloads), which will make development much faster.

Or, if you aren’t planning to make changes to your app (you’re not actively developing it), you just need to generate the correct 0001_initial.py file one time and commit it into the published version of your app. Then, future installs will correctly be able to migrate.


Also, you may already be doing this, but if not: the best way to integrate a django app into Open edX is as a Django app plugin.

Thank you for your response. I will consider your answer and comment again once the bind mount works on my end. But either way, I would like to confirm if it’s true that the problem may exist on the app I’ve created itself.

To be precise, I’ve built my app using the cookiecutter django plugin. So does that mean that I’ve already implemented the Django App Plugin as you’ve mentioned? Based on the Django app plugin, by implementing this, it automatically detects the app to be included in INSTALLED_APPS and include its urls. And that’s what really happened on my app. But why would there be a problem with the models.py? Can I have a detailed instructions on how to implement the django app plugin just to confirm if I’ve skipped any steps and figure out if those steps skipped could also be the probable cause of this error?

There is no problem with models.py. This is just how Django works. Every time you create or change models.py, you need to run makemigrations to create a corresponding “migration” file. The problem is (essentially) that you keep deleting that migration file after it gets created, so it needs to be created over and over again.

Based on what you wrote in your first post, the partners app is installed correctly and is detected by Django. I don’t think you need to worry about that at this time. If it were not installed correctly, you would be seeing different errors - specifically, you wouldn’t see any errors about partners at all, because Django wouldn’t know about it.


If you aren’t familiar with how Django apps work, it would be helpful for you to work through the Django app tutorial first.