Python, MySQL, Django: set the default value for table columns

My tables are listed as models in Python, which then turn into MySQL Django tables. In Python:

class my_table(models.Model):
    is_correct = models.IntegerField(default = 0)

If I insert into this table, I want it to automatically insert 0 for the column is_correct, unless I specify a different value. I also want this to happen if I use raw sql or if I paste from a MySQL stored procedure.

The argument defaultseems to work only with Python. This does not translate into something that MySQL sees. Is it possible?

+3
source share
1 answer

Yes, the argument defaultworks at the django level. If you want to move it to mysql, do the query ALTER TABLE ...manually.

models.IntegerField db_type. ...

+2

All Articles