"Value too long for type character varying(50)" While Adding Data to Replit PostgreSQL

Question:

[2023-11-16 00:42:18,102] ERROR in app: Exception on /register [POST]
Traceback (most recent call last):
  File "/home/runner/New-Star-Cards/venv/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/runner/New-Star-Cards/venv/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/runner/New-Star-Cards/venv/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/runner/New-Star-Cards/venv/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "main.py", line 274, in decorated_function
    return f(*args, **kwargs)
  File "main.py", line 334, in register
    create_user(username, first_name, last_name,
  File "main.py", line 46, in create_user
    cur.execute(
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(50)

When I try to append a string to the Replit PostgreSQL database, it gives me this error. Why?

Hey @RedCoder!

Could you share a link to your Repl so we can look into the error?

Aha! No need – I literally just fixed it! Sorry! Just changed varying(50) to ‘TEXT’.

1 Like

@RedCoder how did you fix it exactly?

^^^ :eyes: Look up ^^^

@RedCoder I mean, like how did you change it to TEXT? (I typed that post before I saw you edit your post)

Umm… its a SQL data type (idk if that is the right term for SQL – I’m new to PostgreSQL).
Ex:

CREATE TABLE IF NOT EXISTS test (
  id SERIAL PRIMARY KEY,
  username TEXT UNIQUE,  -> used to be varying(50)/varying(100)/varying(250)
  password TEXT, -> used to be varying(50)/varying(100)/varying(250)
)

Yes, I know -> isn’t a real comment lol.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.