Skip to content

"value too long for type character varying(2)" error when running build_all() in Docker shell #468

@codybarr

Description

@codybarr

I tried following the guide for running the PokeAPI using docker-compose but when I tried running the build_all() script to populate the database I'm getting an error (see below).

I believe this issue was introduced in 353c405.

I checked out the commit prior to this and was able to run the build_all() script successfully.

Error

>>> from data.v2.build import build_all
>>> build_all()
building pokemon_v2_language
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
psycopg2.DataError: value too long for type character varying(2)


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

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/code/data/v2/build.py", line 1695, in build_all
    _build_languages()
  File "/code/data/v2/build.py", line 143, in _build_languages
    build_generic((Language,), "languages.csv", csv_record_to_objects)
  File "/code/data/v2/build.py", line 102, in build_generic
    model_class.objects.bulk_create(batch)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 459, in bulk_create
    self._batched_insert(objs_with_pk, fields, batch_size)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 1149, in _batched_insert
    inserted_id = self._insert(item, fields=fields, using=self.db, return_id=True)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 1136, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/local/lib/python3.7/site-packages/cachalot/monkey_patch.py", line 32, in inner
    return original(compiler, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/cachalot/monkey_patch.py", line 100, in inner
    return original(write_compiler, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1289, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/cachalot/monkey_patch.py", line 124, in inner
    return original(cursor, sql, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.DataError: value too long for type character varying(2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions