﻿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
34727	Error in CharField with TextChoices and missing max_length parameter	osamahasanone	nobody	"Dear Django Support Team,

I hope this message finds you well. I am writing to report an issue that I encountered while using Django, specifically with the CharField and TextChoices combination when specifying choices but not providing the max_length parameter.

**Issue Description:**

When attempting to add a field of type CharField with TextChoices defined but no max_length parameter in the model, running ./manage.py test USING SQLITE results in the following error:

{{{
django.db.utils.OperationalError: near ""None"": syntax error
}}}


**Reproduction Steps:**


1. Define a Django model with a CharField, TextChoices, and choices, but omit the max_length parameter:


{{{
from django.db import models
from django.utils.text import gettext_lazy as _

class DummyModel(models.Model):
    class DummyFieldChoices(models.TextChoices):
        OPTION1 = 'option1', _('Option 1')
        OPTION2 = 'option2', _('Option 2')
        OPTION3 = 'option3', _('Option 3')

    dummy_field = models.CharField(
        choices=DummyFieldChoices.choices,
        default=DummyFieldChoices.OPTION1,
    )

}}}


2. Run the Django test suite using WITH SQLITE (no issue with Postgres):


{{{
 ./manage.py test
}}}


**Expected Result:**
The Django test suite should run without any errors, and the model should be properly created in the database.


Actual Result:
The Django test suite encounters an OperationalError, with the error message being:


{{{
django.db.utils.OperationalError: near ""None"": syntax error
}}}


**Example of Correct Usage:**


{{{
from django.db import models
from django.utils.text import gettext_lazy as _

class DummyModel(models.Model):
    class DummyFieldChoices(models.TextChoices):
        OPTION1 = 'option1', _('Option 1')
        OPTION2 = 'option2', _('Option 2')
        OPTION3 = 'option3', _('Option 3')

    dummy_field = models.CharField(
        max_length=10,  # Specify the appropriate maximum length for your choices
        choices=DummyFieldChoices.choices,
        default=DummyFieldChoices.OPTION1,
    )


}}}


**Additional Information:**

Django Version: [4.2.3]
Python Version: [3.11.4]
Database: [Sqlite]


I hope this information helps you understand the issue I encountered. If you require any further details or assistance, please do not hesitate to reach out.


Thank you for your attention to this matter, and I look forward to your response.


"	Bug	closed	Testing framework	4.2	Normal	invalid	test, sqlite, CharField, max_length,choices		Unreviewed	0	0	0	0	0	0
