Django makemigrations 错误不可为空的字段
Django makemigrations error non-nullable field
You are trying to add a non-nullable field 'list' to signup 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)
2) Quit, and let me add a default in models.py
这是 ArrayField
以下代码的错误:
from django.contrib.postgres.fields import ArrayField
from django.db import models
class signup(models.Model):
userid=models.CharField(max_length=10)
password=models.CharField(max_length=10)
list=ArrayField(models.IntegerField(null=True,blank=True),size=5)
score=models.IntegerField(default=0)
您必须在数据库中指定 list
可以是 null
:
list=ArrayField(models.IntegerField(null=True, blank=True), size=5, null=True)
You are trying to add a non-nullable field 'list' to signup 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) 2) Quit, and let me add a default in models.py
这是 ArrayField
以下代码的错误:
from django.contrib.postgres.fields import ArrayField
from django.db import models
class signup(models.Model):
userid=models.CharField(max_length=10)
password=models.CharField(max_length=10)
list=ArrayField(models.IntegerField(null=True,blank=True),size=5)
score=models.IntegerField(default=0)
您必须在数据库中指定 list
可以是 null
:
list=ArrayField(models.IntegerField(null=True, blank=True), size=5, null=True)