Search code examples
pythondjangomongodbmigrationdjongo

Error in Django migrations, no changes detected


I've correctly done the "initial setup" with python manage.py migrate command and now in my mongodb database I see these collections:

__schema__
auth_group
auth_group_permissions
auth_permission
auth_user
auth_user_groups
auth_user_user_permissions
django_admin_log
django_content_type
django_migrations
django_session 

with object inside them so I'm pretty sure that I did it correctly and if I do it now it says:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  No migrations to apply.

I think this is all normal, then i created this models.py file

models.py

from django.db import models

# Create your models here.

class Customer(models.Model):
    name = models.CharField(max_length=200, null=True)
    surname = models.CharField(max_length=200, null=True)
    phone = models.CharField(max_length=200, null=True)
    email = models.CharField(max_length=200, null=True)
    date_created = models.DateTimeField(auto_now_add=True, null=True)

Here is part of my settings.py file:

INSTALLED_APPS = [
    'mysite',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

Folder Structure:

mysite
  mysite
    __init__.py
    settings.py
    other files
  polls
    migrations
    other files
      __init__.py 

When I try to do python manage.py makemigrations I get this "No changes detected". Adding my app name doesn't solve the problem. I have a migrations folder with init.py (with the __) in it. I don't understand why it worked for the initial setup and now it doesn't. If i put some syntax error in the models.py file the messages I get after running the commands are the same, so maybe models.py is being searched in another folder? Really don't know, anyway hope i wrote everything necessary, I will reply as fast as I can if you need more informations!


Solution

  • Here is a few things to check to make sure your migrations will go through.

    1. Make sure you created the app using django-admin startapp mysite.
    2. Make sure you've saved the models file after adding the model into the mysite/models.py.
    3. Add the app name to the installed app in the settings.py, but make sure to add it after all apps.

    In your case I see that you've added mysite in the installed app when in reality you should add the app name not the project name, which in your case the polls app.