Home > Software engineering >  It is not possible to migrate a new user element to the django table
It is not possible to migrate a new user element to the django table

Time:08-19

I am faced with the problem that it is not possible to migrate the new user value to the database table. At first there were errors on related_name, but I fixed it, and now that this value cannot be zero, at the same time, if I write that null=True, then the user cannot be displayed in the records in the future.

class Writehelp(models.Model):
    users = models.ForeignKey(User,on_delete = models.CASCADE,related_name='helpedman',null=False,verbose_name='Автор')
    titles = models.CharField(max_length=200, verbose_name='Заголовок', blank=True)
    descriptions = models.TextField(blank=True, verbose_name='Описание')
    createdtimes = models.DateField(auto_now_add=True, db_index=True, verbose_name='Дата создания')
    prices = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='Цена')
    course = models.IntegerField(null=True, blank=True, verbose_name='Курс')
    semestr = models.IntegerField(null=True, blank=True, verbose_name='Семестр')
    subjects = models.CharField(max_length=200, null=True, blank=True, verbose_name='Предмет')
    institutes = models.CharField(max_length=200, null=True, blank=True, verbose_name='Институт')

However, when I migrated this model, there were no problems:

class UploadFile(models.Model):
    user = models.ForeignKey(User,on_delete = models.CASCADE,related_name='file_created' ,verbose_name='Автор')
    title = models.CharField(max_length=200, verbose_name='Заголовок',blank=True)
    # uploadedfile = models.FileField(upload_to='files/',null=True, verbose_name='Файл')
    description = models.TextField(blank=True, verbose_name='Описание')
    createdtime = models.DateField(auto_now_add=True, db_index=True, verbose_name='Дата создания')
    price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='Цена')
    number_course = models.IntegerField(null=True, blank=True, verbose_name='Курс')
    number_semestr = models.IntegerField(null=True, blank=True, verbose_name='Семестр')
    subjectt = models.CharField(max_length=200, null=True,blank=True,verbose_name='Предмет')
    type_materials = models.CharField(max_length=200,null=True,blank=True, verbose_name='Тип работы')
    institute = models.CharField(max_length=200, null=True,blank=True, verbose_name='Институт')

CodePudding user response:

Add defult=None to uploadfile field

  • Related