Django Migration is not applying the migration changes

后端 未结 8 773
悲哀的现实
悲哀的现实 2021-02-02 15:41

Using django 1.7.7 I want to use django\'s migration to add or remove a field. so I modified model.py and ran

python manage.py makemigrations myproj
Migrations f         


        
8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 16:02

    Most of the above solutions would help in the issue, however, I wanted to point out another possible (albeit rare) possibility that the allow_migrate method of database router may be returning False when it should have returned None.

    Django has a setting DATABASE_ROUTERS which will be used to determine which database to use when performing a database query.

    From the docs:

    if you want to implement more interesting database allocation behaviors, you can define and install your own database routers.

    A database router class implements up to four methods:

    • db_for_read(model, **hints)
    • db_for_write(model, **hints)
    • allow_relation(obj1, obj2, **hints)
    • allow_migrate(db, app_label, model_name=None, **hints)

    From the documentation:

    allow_migrate(db, app_label, model_name=None, **hints)

    Determine if the migration operation is allowed to run on the database with alias db. Return True if the operation should run, False if it shouldn’t run, or None if the router has no opinion.

    It is possible that one of the database routers in sequence is returning False for the migration that you're trying to run, in which case the particular operation will not be run.

提交回复
热议问题