2017-10-20 84 views
-1

的主键的名字,当我执行命令无法更改认证表

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

是你的数据库填充?我认为,也许你的用户表被填充,你试图用数据改变结构。

如果该字段不为空,并且在users表中有数据,那么作为数据库约束,您必须执行某些操作。我建议,如果你只是在开发,而不是在生产删除用户表中的数据,然后再次填充它,与新的结构

+0

其实我从头开发应用程序。这里没有表格,我正在进行初始迁移,以便在我的数据库中创建表格。 :( –