Home > front end >  Class Based View - Fields aren't created in database (python Inherits\django cbv)
Class Based View - Fields aren't created in database (python Inherits\django cbv)

Time:01-23

I'm trying create a model inherit following this tutorial: INDEX.HTML showing inherited field

[mysql create only id default field2

project git

CodePudding user response:

According to the Django Documentation for Models, you need to define your database fields as Class attributes.

I.o.w:

class Fish (models.Model):
    
    first_name = models.CharField(max_length=64)
    last_name = models.CharField(max_length=64)
    
    def __init__(self, first_name, last_name="Fish"):
        self.first_name = first_name
        self.last_name  = last_name

Doing so will allow them to be created in the database when you run the migration.

  •  Tags:  
  • Related