The default value for the Django model does not appear in SQL

I created the following test model. The model contains various fields that have a default value .

class TestModel(models.Model):
    name = models.CharField(max_length=32)
    x = models.IntegerField(default=0)
    y = models.IntegerField(default=1, null=True)
    z = models.IntegerField(default=0, null=True, blank=True)

After that, I run the migration command, and Django exports the following migration code. As you can see, the default values ​​are populated using the default parameters .

class Migration(migrations.Migration):

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='TestModel',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('name', models.CharField(max_length=32)),
                ('x', models.IntegerField(default=0)),
                ('y', models.IntegerField(default=1, null=True)),
                ('z', models.IntegerField(default=0, null=True, blank=True)),
            ],
        ),
    ]

And finally, I got the following MySQL code using the Django migration command.

BEGIN;
CREATE TABLE `base_testmodel` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, 
    `name` varchar(32) NOT NULL, 
    `x` integer NOT NULL, 
    `y` integer NULL, 
    `z` integer NULL
    );
COMMIT;

Question . Although I set the default values ​​to 1 and 0, it does not appear in the SQL code. Is this a feature of Django? - or - What am I doing wrong?

+4
source share
1

Django, SQL-, Django.

ORM, , Django . , SQL, , , .

470 SQL, , . , default , . SQL.

, ​​ SQL, alter table .

+6

All Articles