Django 1.7 - makemigrations not detecting changes

前端 未结 29 1320
忘了有多久
忘了有多久 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 12:53

    Maybe that can help someone, I had the same problem.

    I've already created two tables with the serializer class and the views. So when I wanted to updated, I had this error.

    I followed this steps:

    1. I made .\manage.py makemigrations app
    2. I executed .\manage.py migrate
    3. I erased both tables of my models.py
    4. I erased all reference to my tables from serializer and view class.
    5. I executed step 1 and 2.
    6. I retrieved my changes just in the models.py
    7. I executed again step 5.
    8. I restored all my changes.

    If you're working with Pycharm, local history is very helpfull.

    0 讨论(0)
  • 2020-11-27 12:54
    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
    0 讨论(0)
  • 2020-11-27 12:55

    Adding this answer because only this method helped me.

    I deleted the migrations folder run makemigrations and migrate.
    It still said: No migrations to apply.

    I went to migrate folder and opened the last created file,
    comment the migration I wanted(It was detected and entered there)
    and run migrate again.

    This basically editing the migrations file manually.
    Do this only if you understand the file content.

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

    Did u use schemamigration my_app --initial after renaming old migration folder? Try it. Might work. If not - try to recreate the database and make syncdb+migrate. It worked for me...

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

    I had the same problem with having to run makemigrations twice and all sorts of strange behaviour. It turned out the root of the problem was that I was using a function to set default dates in my models so migrations was detecting a change every time I ran makemigrations. The answer to this question put me on the right track: Avoid makemigrations to re-create date field

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

    The answer is on this stackoverflow post, by cdvv7788 Migrations in Django 1.7

    If it is the first time you are migrating that app you have to use:

    manage.py makemigrations myappname Once you do that you can do:

    manage.py migrate If you had your app in database, modified its model and its not updating the changes on makemigrations you probably havent migrated it yet. Change your model back to its original form, run the first command (with the app name) and migrate...it will fake it. Once you do that put back the changes on your model, run makemigrations and migrate again and it should work.

    I was having the exact same trouble and doing the above worked perfectly.

    I had moved my django app to cloud9 and for some reason I never caught the initial migration.

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