Django 1.7 - makemigrations not detecting changes

前端 未结 29 1297
忘了有多久
忘了有多久 2020-11-27 12:43

As the title says, I can\'t seem to get migrations working.

The app was originally under 1.6, so I understand that migrations won\'t be there initially, and indeed i

相关标签:
29条回答
  • 2020-11-27 13:12

    You want to check the settings.py in the INSTALLED_APPS list and make sure all the apps with models are listed in there.

    Running makemigrations in the project folder means it will look to update all the tables related to all the apps included in settings.py for the project. Once you include it, makemigrations will automatically include the app (this saves a lot of work so you don't have to run makemigrations app_name for every app in your project/site).

    0 讨论(0)
  • 2020-11-27 13:12

    Just in case you have a specific field that does not get identified by makemigrations: check twice if you have a property with the same name.

    example:

    field = django.db.models.CharField(max_length=10, default = '', blank=True, null=True)
    
    # ... later
    
    @property
    def field(self):
        pass
    

    the property will "overwrite" the field definition so changes will not get identified by makemigrations

    0 讨论(0)
  • 2020-11-27 13:12

    Added this answer because none of other available above worked for me.

    In my case something even more weird was happening (Django 1.7 Version), In my models.py I had an "extra" line at the end of my file (it was a blank line) and when I executed the python manage.py makemigrations command the result was: "no changes detected".

    To fix this I deleted this "blank line" that was at the end of my models.py file and I did run the command again, everything was fixed and all the changes made to models.py were detected!

    0 讨论(0)
  • 2020-11-27 13:13

    You may need to fake the initial migrations using the command below

    python manage.py migrate --fake-initial
    
    0 讨论(0)
  • 2020-11-27 13:13

    In my case I needed to add my model to the _init_.py file of the models folder where my model was defined:

    from myapp.models.mymodel import MyModel
    
    0 讨论(0)
提交回复
热议问题