Django - makemigrations - No changes detected

前端 未结 30 1516
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 04:44

I was trying to create migrations within an existing app using the makemigrations command but it outputs \"No changes detected\".

Usually I create new apps using the

30条回答
  •  Happy的楠姐
    2020-12-02 05:43

    A very dumb issue you can have as well is to define two class Meta in your model. In that case, any change to the first one won't be applied when running makemigrations.

    class Product(models.Model):
        somefield = models.CharField(max_length=255)
        someotherfield = models.CharField(max_length=255)
    
        class Meta:
            indexes = [models.Index(fields=["somefield"], name="somefield_idx")]
    
        def somefunc(self):
            pass
    
        # Many lines...
    
        class Meta:
            indexes = [models.Index(fields=["someotherfield"], name="someotherfield_idx")]
    

提交回复
热议问题