3

My tables are specified as models in Python, which are then made into MySQL tables by Django. In Python:

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

If I do an insert into this table then 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 am using raw sql or if I am inserting from a MySQL stored procedure.

The default argument only seems to work from within Python. It's not translated into anything that MySQL sees. Is such a thing possible?

1
  • This seems to be a problem that the Django project has decided to classify as wontfix. Commented Mar 12, 2013 at 20:15

1 Answer 1

2

Yes, default argument works on django level. If you want to move it to mysql, perform ALTER TABLE ... query manually.

You also can try to extend models.IntegerField and override db_type. But it should be done for every field...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.