You are trying to add a non-nullable field without a default

2022-09-30 04:44:45 浏览数 (1)

integer

代码语言:javascript复制
You are trying to add a non-nullable field 'unique_key' to h1_send_beforeamp without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py

代码语言:javascript复制
class amp(BaseModel):
    unique_key = models.AutoField(primary_key=True, verbose_name='Primary key') 

対策:

追加「auto_created=True, 」

代码语言:javascript复制
class amp(BaseModel):
    unique_key = models.AutoField(primary_key=True, auto_created=True, verbose_name='Primary key')

char

追加「 default='default value' 」

代码语言:javascript复制
str = models.CharField(max_length=20, verbose_name='受注ID', default='')

0 人点赞