我正在运行一个Django 1.4.2项目。我有一个类为User(models.Model)的数据库,并且现在想要更改这个模型,以便使用django.contrib.auth.models中内置的模型User。我可以简单地使用现有代码并使我的自定义User模型成为Django内置模型的子类吗?以下是现有的模型。
class User(models.Model):
u_id = models.AutoField(primary_key=True)
#password = models.CharField(max_length=765)
old_password = models.CharField(max_length=765, null=True, blank=True)
birthday = models.DateField(null=True, blank=True)
school_year = models.CharField(max_length=765, blank=True)
gender = models.CharField(max_length=18, blank=True)
#email = models.CharField(max_length=765, blank=True)
profile_pic = models.CharField(max_length=765, blank=True)
is_cloudinary_pic = models.BooleanField(default=False)
fb_id = models.CharField(max_length=765, blank=True)
phone_num = models.CharField(max_length=765, blank=True)
name = models.CharField(max_length=765, blank=True)
confirmcode = models.CharField(max_length=765, blank=True)
status = models.CharField(max_length=765, blank=True)
netid = models.CharField(max_length=765, blank=True)
favorites = models.ManyToManyField('listings.Listing', blank=True, related_name='favorites')
stripe = models.CharField(max_length=765, blank=True)
rating = models.IntegerField(null=True, blank=True)
preferences = models.CharField(max_length=765, blank=True)
b_notification = models.CharField(max_length=765, blank=True)
l_notification = models.CharField(max_length=765, blank=True)
address = models.CharField(max_length=765, blank=True)
city = models.CharField(max_length=765, blank=True)
state = models.CharField(max_length=6, blank=True)
zip = models.CharField(max_length=15, blank=True)
emailprefs = models.CharField(max_length=30, blank=True)
exp_month = models.CharField(max_length=6, blank=True)
exp_year = models.CharField(max_length=12, blank=True)
last4 = models.CharField(max_length=12, blank=True)
c_type = models.CharField(max_length=765, blank=True)
user_type = models.CharField(max_length=10, blank=True)
contract = models.ForeignKey('contracts.Contract', null=True,blank=True, default=None, on_delete=models.SET_NULL)
last_listing_booked = models.ForeignKey('listings.Listing', null=True,blank=True, default=None, on_delete=models.SET_NULL, related_name='last_listing_booked')
last_locked_on = models.IntegerField(null=True, blank=True)
waitlist_number = models.IntegerField(null=True, blank=True)
waitlist_listing = models.ForeignKey('listings.Listing', null=True, blank=True, on_delete=models.SET_NULL, related_name='waitlist_listing')
uploaded_contract = models.FileField(upload_to=contract_file_name, max_length=765, null=True, blank=True, default=None, storage=FileSystemStorage(location=os.path.join(MEDIA_ROOT, 'contracts')))
当我尝试使用Django South进行迁移时,将我的模型设为Django用户模型的子类后,我被要求设置user_ptr的值,这是一个关于它我无法找到任何信息的字段。
一般来说,简单地采用这种子类化方式是否不安全?我不能承受失去已经拥有的所有用户数据并重新开始。请注意,密码和电子邮件字段被注释掉,因为它们与Django版本的这些字段冲突。