Default values in the model - Django

Asked

Viewed 183 times

0

I am studying Jango and trying to set a standard value for a field when makemigrations is executed, would inform that such field would receive a default value like 0

models.IntegerField(default=0)

It turns out that Preset is defined as None

I don’t understand, the documentation says everything but what I want.

models.IntegerField(default=0)

The default is set to 0 as well.

My model:

class User(models.Model):
  # User fields for login
  username = models.CharField(max_length=30)
  gender   = models.IntegerField(default=0)
  status   = models.IntegerField(default=0)
  premium  = models.IntegerField(default=0)
  ip       = models.CharField(max_length=50)

Where default=0 would be the default value for the field

  • Shows your definition of the models involved, explains better what is happening that you would not like to happen, what is the warging msg or error if there is.

  • @Sidon edited the post

  • But did not explain the "problem", some error msg? in time: User is already a model of Django, vc can extend it but not in the way you are doing.

1 answer

0

Considering a different table than User, there is nothing wrong with your code, what is missing is to run a command, you have to run, in this order:

  • python Manage.py makemigrations
  • python Manage.py migrate

Browser other questions tagged

You are not signed in. Login or sign up in order to post.