Understanding error django.db.utils.DataError: value too long for type character varying(25)

I am trying to migrate my models to the database using the make migrations and migrate command. It says that there is one value that needs more than 25 character spaces. So I raised all of the max_length properties to 35 and I am still getting this issue with it saying that the limit is 25? Did I not target something correctly? I used control f to find all instances and update to 35, but somehow this error persists.

models.py

from django.db import models

# makemigrations and migrate from manage.py
# Create your models here.

# Tie everything with Quote ID


# customer model
class Customer(models.Model):
    # columns would be the variables
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    date_of_birth = models.DateField()
    address = models.CharField(max_length=50)
    telephone_number = models.IntegerField()
    zip_code = models.CharField(default=00000)
    email_address = models.CharField(max_length=50)
    home_ownership_options = (("OWN", "Owns_Property"), ("RENT", "Rents_Property"))
    home_ownership = models.CharField(max_length=50, choices=home_ownership_options)


# credit
# vehicle model
#
class Vehicle(models.Model):
    Vehicle_Identification_Number = models.CharField(max_length=30)
    # Enumerate Technique The first item in the tuple is what will be listed in the database.
    # The second item in the tuple is what will display for the user.
    Usage_Type_Options = (
        ("PLEASURE", "Pleasure Vehicle"),
        ("WORK", "Work/School"),
        ("BUSINESS", "Business"),
        ("COMMERCIAL", "Commercial"),
    )
    Usage_Type = models.CharField(choices=Usage_Type_Options, max_length=11, blank=True)
    Annual_Mileage = models.IntegerField()
    Year = models.IntegerField()
    Make = models.CharField(max_length=30)
    Model = models.CharField(max_length=30)


class Drivers(models.Model):

    Driver_Name = models.CharField(max_length=50)
    driver_relation_options = (
        (
            ("SELF, Self"),
            ("GRANDFATHER", "Grandfather"),
            ("GRANDMOTHER", "Grandmother"),
            ("SPOUSE", "Spouse"),
            ("DOMESTIC PARTNER", "Domestic Partner"),
            ("SON", "Son"),
            ("DAUGHTER", "Daughter"),
            ("FIANCE", "Fiance"),
            ("FRIEND", "Friend"),
            ("OTHER", "Other"),
        ),
    )

    Driver_Relation = models.CharField(driver_relation_options, max_length=50)

    state_options = (
        ("AL", "Alabama"),
        ("AK", "Alaska"),
        ("AZ", "Arizona"),
        ("AR", "Arkansas"),
        ("CA", "California"),
        ("CO", "Colorado"),
        ("CT", "Connecticut"),
        ("DC", "Washington D.C."),
        ("DE", "Delaware"),
        ("FL", "Florida"),
        ("GA", "Georgia"),
        ("HI", "Hawaii"),
        ("ID", "Idaho"),
        ("IL", "Illinois"),
        ("IN", "Indiana"),
        ("IA", "Iowa"),
        ("KS", "Kansas"),
        ("LA", "Louisiana"),
        ("ME", "Maine"),
        ("MD", "Maryland"),
        ("MA", "Massachusetts"),
        ("MI", "Michigan"),
        ("MN", "Minnesota"),
        ("MS", "Mississippi"),
        ("MO", "Missouri"),
        ("MT", "Montana"),
        ("NE", "Nebraska"),
        ("NV", "Nevada"),
        ("NH", "New Hampshire"),
        ("NJ", "New Jersey"),
        ("NM", "New Mexico"),
        ("NY", "New York"),
        ("NC", "North Carolina"),
        ("ND", "North Dakota"),
        ("OH", "Ohio"),
        ("OK", "Oklahoma"),
        ("OR", "Oregon"),
        ("PA", "Pennsylvania"),
        ("PR", "Puerto Rico"),
        ("RI", "Rhode Island"),
        ("SC", "South Carolina"),
        ("SD", "South Dakota"),
        ("TN", "Tennessee"),
        ("TX", "Texas"),
        ("UT", "Utah"),
        ("VT", "Vermont"),
        ("VA", "Virginia"),
        ("WA", "Washington"),
        ("WI", "Wisconsin"),
        ("WY", "Wyoming"),
    )

    Drivers_License_State = models.CharField(state_options, max_length=30)

    Drivers_License_Number = models.CharField(max_length=30)

    drivers_license_options = (
        ("ACTIVE LICENSE", "Active License"),
        ("LEARNERS PERMIT", "Permit License"),
        ("COMMERCIAL LICENSE", "Commerical License"),
        ("FOREIGN LICENSE", "Foreign License"),
        ("INTERNATION LICENSE", "International License"),
        ("SUSPENDED LICENSE", "Suspended License"),
        ("EXPIRED LICENSE", "Expired License"),
        ("NOT LICENSED TO DRIVE", "Not licensed to drive"),
    )
    Drivers_License_Status = models.CharField(drivers_license_options, max_length=50)

    gender_options = (
        ("MALE", "Male"),
        ("FEMALE", "Female"),
        ("NONBINARY", "NonBinary"),
        ("NOANSWER", "Prefer Not to Answer"),
    )
    gender = models.CharField(gender_options, max_length=30)

    date_of_issuance = models.DateField()

    job_status_options = (
        ("FULL_TIME_EMPLOYED", "Full Time Employed"),
        ("PART_TIME_EMPLOYED", "Part Time Employed"),
        ("STUDENT", "Student"),
        ("HOMEMAKER", "Homemaker"),
        ("UNEMPLOYED", "Unemployed"),
    )

    job_status = models.CharField(job_status_options, max_length=50)

    education_options = (
        ("LESS THAN HIGHSCHOOL", "Less than highschool"),
        ("HIGHSCHOOL", "Highschool"),
        ("VOCATIONAL", "Vocational"),
        ("ASSOCIATE", "Associate"),
        ("Bachelors", "Bachelors"),
        ("PHD", "Phd"),
        ("DOCTORS", "Doctor"),
        ("LAWYER", "Lawyer"),
    )
    education = models.CharField(education_options, max_length=35)

    affilation_options = (("DFW_PYTHONEERS", "Dfw_Pythoneers"),)

    affilation = affilation_options


# many to many relationship QUOTE to PRODUCT
# state of texas requirements (LIABLITY,PIP,)
class Product(models.Model):
    product_type_options = (
        ("LIABILITY", "Liability"),
        ("RECCOMENDED_COVERAGE", "Reccomended Coverage"),
        ("CUSTOM", "Custom"),
    )
    coverage_options = (("FULL_COVERAGE", "Full Coverage"),)


# adding products to customers
# if not defined in a table before than you must use quotes for the model not defined.
# since everything is already defined already we do not need to worry about that.
class Quote(models.Model):
    Customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
    Vehicles = models.ForeignKey(Vehicle, on_delete=models.CASCADE)
    Drivers = models.ForeignKey(Drivers, on_delete=models.CASCADE)
    Reference_Number = models.CharField(max_length=30)
    Price = models.DecimalField(max_digits=7, decimal_places=2)

Error message

$ python manage.py migrate 
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, quote, sessions
Running migrations:
  Applying quote.0003_remove_drivers_drivers_license_and_more...Traceback (most recent call last):
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\backends\utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(25)


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\manage.py", line 22, in <module>
    main()
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\core\management\base.py", line 
413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\core\management\base.py", line 
459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\core\management\base.py", line 
107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\core\management\commands\migrate.py", line 356, in handle
    post_migrate_state = executor.migrate(
                         ^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\migrations\executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\migrations\executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
            ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\migrations\executor.py", line 252, in apply_migration
    state = migration.apply(state, schema_editor)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\migrations\migration.py", line 132, in apply
    operation.database_forwards(
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\migrations\operations\fields.py", line 108, in database_forwards
    schema_editor.add_field(
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\backends\base\schema.py", line 756, in add_field
    self.execute(sql, params or None)
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\backends\postgresql\schema.py", line 48, in execute
    return super().execute(sql, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\backends\base\schema.py", line 202, in execute
    cursor.execute(sql, params)
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\backends\utils.py", line 122, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\backends\utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\backends\utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\backends\utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\Andrew\Desktop\django_projects\django_insurance\env\Lib\site-packages\django\db\backends\utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.DataError: value too long for type character varying(25)

utilizing chat gpt and having it break down the error message line for line it told me there was a problem with an earlier migration. i deleted the migrations completely and tried again and it worked. i should probably be more careful with deleting things but again its non real data so i should be okay in this case.

1 Like