Django 1.7 - makemigrations not detecting changes

前端 未结 29 1298
忘了有多久
忘了有多久 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:00

    People like me who don't like migrations can use steps below.

    1. Remove changes what you want to sync.
    2. Run python manage.py makemigrations app_label for the initial migration.
    3. Run python manage.py migrate for creating tables before you make changes.
    4. Paste changes which you remove at first step.
    5. Run 2. and 3. steps.

    If you confused any of these steps, read the migration files. Change them to correct your schema or remove unwanted files but don't forget to change next migration file's dependencies part ;)

    I hope this will help someone in future.

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

    I recently upgraded Django from 1.6 to 1.8 and had few apps and migrations for them. I used south and schemamigrations for creating migrations in Django 1.6, which is dropped in Django 1.8.

    When I added new models after upgrade, the makemigrations command wasn't detecting any changes. And then I tried the solution suggested by @drojf (1st answer), it worked fine, but failed to apply fake initial migration (python manage.py --fake-initial). I was doing this as my tables (old tables) were already created.

    Finally this worked for me, removed new models (or model changes) from models.py and then had to delete (or rename for safety backup) migrations folder of all apps and run python manage.py makemigrations for all apps, then did python manage.py migrate --fake-initial. This worked like a charm. Once initial migration is created for all apps and fake initial migrated, then added new models and followed regular process of makemigrations and migrate on that app. The changes were detected now and everything went fine.

    I just thought of sharing it here, if someone faces same problem (having schemamigrations of south for their apps), it might help them :)

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

    Ok, looks like I missed an obvious step, but posting this in case anyone else does the same.

    When upgrading to 1.7, my models became unmanaged (managed = False) - I had them as True before but seems it got reverted.

    Removing that line (To default to True) and then running makemigrations immediately made a migration module and now it's working. makemigrations will not work on unmanaged tables (Which is obvious in hindsight)

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

    Adding my 2c, since none of these solutions worked for me, but this did...

    I had just run manage.py squashmigrations and removed the old migrations (both the files and lines in the the django.migrations database table).

    This left a line like this in the last migration file:

    replaces = [(b'my_app', '0006_auto_20170713_1735'), (b'my_app', '0007_auto_20170713_2003'), (b'my_app', '0008_auto_20170713_2004')]
    

    This apparently confused Django and caused weird behavior: running manage.py makemigrations my_app would recreate the initial migration as if none existed. Removing the replaces... line fixed the problem!

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

    If you're changing over from an existing app you made in django 1.6, then you need to do one pre-step (as I found out) listed in the documentation:

    python manage.py makemigrations your_app_label

    The documentation does not make it obvious that you need to add the app label to the command, as the first thing it tells you to do is python manage.py makemigrations which will fail. The initial migration is done when you create your app in version 1.7, but if you came from 1.6 it wouldn't have been carried out. See the 'Adding migration to apps' in the documentation for more details.

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

    First this solution is applicable to those who are facing the same issue during deployment on heroku server, I was facing same issue.

    To deploy, there is a mandatory step which is to add django_heroku.settings(locals()) in settings.py file.

    Changes: When I changed the above line to django_heroku.settings(locals(), databases=False), it worked flawlessly.

    0 讨论(0)
提交回复
热议问题