当我执行命令
时python manage.py makemigrations
结果是
You are trying to add a non-nullable field 'pk_bint_user_id' to appuser 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
我的模型如下所示:
class AppUser(AbstractBaseUser):
pk_bint_user_id = models.BigIntegerField(primary_key=True)
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
fk_bint_travel_agency_user_id_or_corporate_user_id= models.BigIntegerField(blank=True,null=True)
chr_travel_agency_user_or_corporate_user =models.CharField('Agency user or Corporate user',max_length=5,blank=True,null=True)
chr_user_type = models.CharField('User type code',max_length=5,blank=True,null=True)
vchr_account_type=models.CharField('Account type',max_length=5,blank=True,null=True)
vchr_account_status=models.CharField('Account status',max_length=5,blank=True,null=True)
objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
class Meta:
db_table='tbl_user'
我想将主键自定义为与“id”,
不同的名称答案 0 :(得分:0)
是否填充了您的数据库?我想也许您的用户表已填充,并且您正在尝试使用数据更改结构。
如果该字段不为null并且您在users表中有数据,则作为数据库约束,您必须执行某些操作。我建议如果您只是在开发而不是生产中,请从用户表中删除数据,然后使用新结构再次填充