Django Models with default value in another branch

1

I'm having a field that I've added to another branch (which is in developing status ) calling money , with default value: 0.00 in the User model. However, it is not yet being used in the production branch.

Today when I went to do a test to create an account, I received the following error:

IntegrityError at /users/register
(1364, "Field 'money' doesn't have a default value")

I noticed that in my MySQL there is still the money field that I created in another branch. However, in the database it does not have a default value.

class User(AbstractUser):
    ...
    money = models.DecimalField(max_digits=8, decimal_places=2, null=True, default=0.00)

I would like to understand why Django did not default to MySQL 0.00. This is causing a problem in account creation, but it should not have been created as a default value. Does Django manually default value ?

    
asked by anonymous 08.01.2018 / 20:00

1 answer

1

Actually, Django sets the default value by code. I think the reason is because it is possible to pass a function to the default value, something that would not be feasible to do generically for all databases.

On your problem, ideally you should rebuild your database by changing branches, as this would ensure that your database complies with the current implementation, this avoids a lot of headaches.

    
08.01.2018 / 21:14