Django makemigrations says "No changes detected in app"

Hi There!

I made a bunch of changes to my models locally and ran makemigrations and migrate commands localy. Locally everything runs smooth.
After that I did ‘fly deploy’ which succeeded. Then I ran the command
fly ssh console -C "python manage.py makemigrations my_app"
and to my surprise it says “No changes were detected”. I also get a bunch of errors when I ran migrate after that just to see.

Can anyone help with this issue? Why is it not picking up the modeling changes in the fly deployment? Thanks!

Hi @SidR !

If you ran makemigration locally and then deployed all the changes, your new migration should have been applied.

Check your fly.toml if you are applying the migrations on deployment, you should have this:

[deploy]
  release_command = "python manage.py migrate"

If so, you migration are applied automatically during deployment (fly deploy).

makemigration command creates the new migration files. You should create the new migration files locally and deploy them to production. In production you should just apply (migrate) them - manually, with fly ssh console -C "python manage.py migrate my_app" or automatically, with the release_command on fly.toml (as mentioned before).

You can also check if the migrations were applied by doing:

fly ssh console -C "python manage.py showmigrations my_app"

More about showmigrations command here.

Hi @katia thanks for the reply. I checked the showmigrations output and see that the last 2 migrations haven’t been applied. I actually changed the base auth User model and implemented my custom one using AbstractUser. Perhaps there’s an issue with the migration on the fly node due to some conflicts related to this. The app is still in dev phase. Is there anything I can do to force apply the latest model changes?

Also my fly.toml doesn’t have release_command = “python manage.py migrate”

If you don’t have the release_command to apply the migration automatically, you should be able to apply the migration manually with:

fly ssh console -C "python manage.py migrate my_app"

Did you try that?

@katia Thanks for the reply. Yes and it didn’t work. Like I mentioned, I introduced a custom User model. I did all of the migration on local and tested the app on my local machine. Then I ran the following commands

  1. fly deploy
  2. fly ssh console -C “python manage.py makemigrations my_app”
    - here the output was that “no changes were detected”
  3. fly ssh console -C “python /code/manage.py migrate”

When I ran 3, it complained that "...'my_app' doesn't provide model 'custom_user'..." at a bunch of places…
I didn’t face this issue when I migrated locally. What can I do to resolve this on the fly deployment?

That’s correct. When you deploy your app, all the changes are should be there (including the new migration files).

Can you check your local migration and production migration and post them here?
You can run python manage.py showmigrations my_app in your local and then fly ssh console -C "python manage.py showmigrations my_app" to compare them.

@katia To provide some additional context on migrations, there are the migrations that haven’t been applied on fly deployment (but on my local they’re all applied successfully)

Output of fly ssh console -C “python manage.py showmigrations my_app”

...
...
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
authtoken
 [ ] 0001_initial
 [ ] 0002_auto_20160226_1747
 [ ] 0003_tokenproxy
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
my_app
 [X] 0001_initial
 [X] 0002_auto_20230727_0219
 [X] 0003_auto_20230728_0650
 [X] 0004_alter_profile_uid
 [ ] 0005_auto_20230729_1919
 [ ] 0006_alter_userprofile_uid
 [ ] 0007_auto_20230731_0859
sessions
 [X] 0001_initial
...
...

And what do you have when you run python manage.py showmigrations my_app locally?

@katia Here’s the output from my local

account
 [X] 0001_initial
 [X] 0002_email_max_length
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
 [X] 0010_alter_group_name_max_length
 [X] 0011_update_proxy_permissions
 [X] 0012_alter_user_first_name_max_length
authtoken
 [X] 0001_initial
 [X] 0002_auto_20160226_1747
 [X] 0003_tokenproxy
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
my_app
 [X] 0001_initial
 [X] 0002_auto_20230727_0219
 [X] 0003_auto_20230728_0650
 [X] 0004_alter_profile_uid
 [X] 0005_auto_20230729_1919
 [X] 0006_alter_userprofile_uid
 [X] 0007_auto_20230731_0859
sessions
 [X] 0001_initial
sites
 [X] 0001_initial
 [X] 0002_alter_domain_unique

Strangely when I just re-ran this cmd fly ssh console -C "python manage.py showmigrations my_app"
All I got was :

my_app
 [X] 0001_initial
 [X] 0002_auto_20230727_0219
 [X] 0003_auto_20230728_0650
 [X] 0004_alter_profile_uid
 [ ] 0005_auto_20230729_1919
 [ ] 0006_alter_userprofile_uid
 [ ] 0007_auto_20230731_0859

There rest of the migrations I pasted above (from yesterday) are not showing up in the fly deployment

That’s correct. The command shows the migration only for my_app app. To show all, you can run `fly ssh console -C “python manage.py showmigrations”``.

As you mentioned that you got:

"...'my_app' doesn't provide model 'custom_user'..."

you might want to check if AUTH_USER_MODEL in your settings is correct:

# settings.py
AUTH_USER_MODEL = "my_app.YourCustomUserModel"

and check all the references you have.

That doesn’t look like a deployment issue but rather a some misconfiguration in the Django project.

Did you change anything in those non-applied migration files after you applied them locally?

 [ ] 0005_auto_20230729_1919
 [ ] 0006_alter_userprofile_uid
 [ ] 0007_auto_20230731_0859

@katia I have the correct AUTH_USER_MODEL in settings.py. I also didn’t change anything in the non-applied migration files (or any migration files for that matter).
If the django project was misconfigured, then I should have seen errors when I ran it locally, right?
I tested the app locally end to end and its working as expected.

Yes, most likely you would see the same errors in your local machine. Did you check the logs?

fly logs -a <your-app-name>

I was thinking about this issue. Is there any reason you don’t have the release command on fly.toml?

Can you add:

[deploy]
  release_command = "python manage.py migrate"

Here is an example.

And try to deploy again. This should run the migration before the release is deployed, which is good for applying migrations. More about it, here.

Thanks @katia. I’ve added that to the toml file. I had to actually nuke the entire project on fly and recreate it unfortunately. Since I’m still in dev mode I didn’t have to worry about data migrations, etc. Now it works fine. Hopefully I don’t run into this in the futue.