Django migration error :you cannot alter to or from M2M fields, or add or remove through= on M2M fields

后端 未结 7 1644
梦如初夏
梦如初夏 2020-12-12 18:48

I\'m trying to modify a M2M field to a ForeignKey field. The command validate shows me no issues and when I run syncdb :

ValueError: Cannot alter field xxx i         


        
7条回答
  •  無奈伤痛
    2020-12-12 19:39

    If you're still developing the application, and don't need to preserve your existing data, you can get around this issue by doing the following:

    1. Delete and re-create the db.

    2. go to your project/app/migrations folder

    3. Delete everything in that folder with the exception of the init.py file. Make sure you also delete the pycache dir.

    4. Run syncdb, makemigrations, and migrate.

提交回复
热议问题