﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35509	migration models.BooleanField(default=False) does not create a DEFAULT attribte on mysql table	Daniel Ahern	nobody	"Python 3.12.0
Django 5.0.6
MariaDB/MySQL 8.0.30-0ubuntu0.22.04.1 (Ubuntu)

models.py:

{{{
from django.db import models

class TableBoolean(models.Model):
    field1 = models.BooleanField(default=False)

    class Meta:
        db_table = 'test_boolean'
}}}

Then I do:

python manage.py makemigrations v506

which makes:

{{{
# Generated by Django 5.0.6 on 2024-06-08 14:03

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='TableBoolean',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('field1', models.BooleanField(default=False)),
            ],
            options={
                'db_table': 'test_boolean',
            },
        ),
    ]
}}}

Running the migration creates a table that does NOT have a default value:

{{{
mysql> describe test_boolean;
+--------+------------+------+-----+---------+----------------+
| Field  | Type       | Null | Key | Default | Extra          |
+--------+------------+------+-----+---------+----------------+
| id     | bigint     | NO   | PRI | NULL    | auto_increment |
| field1 | tinyint(1) | NO   |     | NULL    |                |
+--------+------------+------+-----+---------+----------------+
}}}

I am able to alter the table:

{{{
mysql> alter table test_boolean modify field1 boolean default 0;
Query OK, 0 rows affected (0.07 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe test_boolean;
+--------+------------+------+-----+---------+----------------+
| Field  | Type       | Null | Key | Default | Extra          |
+--------+------------+------+-----+---------+----------------+
| id     | bigint     | NO   | PRI | NULL    | auto_increment |
| field1 | tinyint(1) | YES  |     | 0       |                |
+--------+------------+------+-----+---------+----------------+
}}}"	Bug	closed	Database layer (models, ORM)	5.0	Normal	invalid		Daniel Ahern	Unreviewed	0	0	0	0	0	0
