Django 1.7 - “No migrations to apply” when run migrate after makemigrations

后端 未结 15 1549
离开以前
离开以前 2020-11-28 20:46

I use Django1.7 with Mezzanine. I create simple profile (according to Mezzanine documentation) stored in separate app \"profiles\":

class RoadmapProfile(mode         


        
相关标签:
15条回答
  • 2020-11-28 21:28

    Maybe your model not linked when migration process is ongoing. Try to import it in file urls.py from models import your_file

    0 讨论(0)
  • 2020-11-28 21:30

    For me, none of the offered solutions worked. It turns out that I was using different settings for migration (manage.py) and running (wsgi.py). Settings defined in manage.py used a local database however a production database was used in wsgi.py settings. Thus a production database was never migrated. Using:

    django-admin migrate
    

    for migration proved to be better as you have to specify the settings used as here.

    • Make sure that when migrating you always use the same database as when running!
    0 讨论(0)
  • 2020-11-28 21:31

    Sounds like your initial migration was faked because the table already existed (probably with an outdated schema):

    https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-migrations-to-apps

    "This will make a new initial migration for your app. Now, when you run migrate, Django will detect that you have an initial migration and that the tables it wants to create already exist, and will mark the migration as already applied."

    Otherwise you would get an no-such-table error :)

    [edit] did you clean up the applied-migrations table? That's also a common cause for non-applied migrations.

    0 讨论(0)
  • 2020-11-28 21:31

    if you are using GIT for control versions and in some of yours commit you added db.sqlite3, GIT will keep some references of the database, so when you execute 'python manage.py migrate', this reference will be reflected on the new database. I recommend to execute the following command:

    git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch 'db.sqlite3' HEAD
    

    it worked for me :)

    0 讨论(0)
  • 2020-11-28 21:34

    My issue was that there was no __init__.py file in the same folder as the migrations. On adding the __init__.py to the folder which contained them, manage.py migrate found and ran them.

    0 讨论(0)
  • 2020-11-28 21:35

    1- run python manage.py makemigrations <appname>

    2- run python manage.py sqlmigrate <appname> <migrationname> - you will find migrationname in migration folder under appname (without '.py' extension of course)

    3- copy all text of result # all sql commands that generated
    4- go to your db ide and paste as new query and run it

    now all changes are applied on your db

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