django migrate 拋出異常:ValueError: Found wrong number (0) of constraints for …


問題描述:

  修改了 Meta 的 unique_together 屬性,makemigrations 的時候,能正常進行,但是當進行 migrate 的時候就拋出了 ValueError: Found wrong number (0) of constraints for …

解決辦法:

  參考自 https://stackoverflow.com/questions/41623515/received-valueerror-found-wrong-number-0-of-constraints-for-during-djan

  因為修改了唯一約束索引,If you look at your actual table (use \d table_name) and look at the indexes, you'll find an entry for your unique constraint. This is what Django is trying to find and drop. But it can't find an exact match(Postgres and MySQL Answer)

  找到在修改 unique_together 之前的包含 AlterUniqueTogether 的 migrations 文件,將上面的 unique_together 參數值,修改成與當前一致(增加或者刪減,或者字段順序)

  修改完成以后,直接 migrate 即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM