Django fixture fails, stating “DatabaseError: value too long for type character varying(50)”

前端 未结 6 1052
时光取名叫无心
时光取名叫无心 2020-12-05 19:57

I have a fixture (json) which loads in development environment but fails to do so in server environment. The error says: \"DatabaseError: value too long for type chara

6条回答
  •  Happy的楠姐
    2020-12-05 20:12

    Well, what makes the difference is the encoding of the template databases. On the production server they had ascii encoding while on the dev box it is utf-8.

    By default postgres creates a database using the template1. My understanding is that if its encoding is not utf-8, then the database you create will have this issue, even though you create it with utf-8 encoding.

    Therefore I dropped it and recreated it with its encoding set to UTF8. The snippet below does it (taken from here):

    psql -U postgres 
    
    UPDATE pg_database SET datallowconn = TRUE where datname = 'template0';
    \c template0
    UPDATE pg_database SET datistemplate = FALSE where datname = 'template1';
    drop database template1;
    create database template1 with template = template0 encoding = 'UNICODE';
    UPDATE pg_database SET datistemplate = TRUE where datname = 'template1';
    \c template1
    UPDATE pg_database SET datallowconn = FALSE where datname = 'template0';
    

    Now the fixture loads smoothly.

提交回复
热议问题