添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
class PushApplication(models.Model):
    jws_key = models.CharField(blank=True, max_length=255)
I changed it to a BinaryField:
class PushApplication(models.Model):
    jws_key = models.BinaryField(blank=True)
When I tried to run makemigrations:
$ python manage.py makemigrations
django.core.exceptions.FieldError: Unknown field(s) (jws_key) specified for PushApplication
The problem was that I had a ModelForm with jws_key in the fields:
class PushAppForm(ModelForm):
    class Meta:
        fields = ['name', 'jws_key']
I removed jws_key from the ModelForm and it works.
But the error message sent me on an hour long web search trying to find out why changing a CharField to BinaryField would break migrations.
In fact the exception you encountered has nothing to do with makemigrations; you should be able to also trigger it by simply importing the module defining the PushAppForm form class.
The reason behind the FieldError on PushAppForm creation is the fact BinaryField are not editable by default for obvious reasons and such fields are ignored by model forms.
I suggest we adjust the message of the FieldError raised when an existing editable=False field is explicitly specified through Meta.fields and amend the BinaryField's limitations documentation to also mention it can't be used in forms by default.