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

后端 未结 7 1647
梦如初夏
梦如初夏 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:27

    I literally had the same error for days and i had tried everything i saw here but still didn'y work. This is what worked for me:

    • I deleted all the files in migrations folder exceps init.py
    • I also deleted my database in my case it was the preinstalled db.sqlite3 After this, i wrote my models from the scratch, although i didn't change anything but i did write it again.
    • Apply migrations then on the models and this time it worked and no errors.

提交回复
热议问题