DatabaseError: value too long for type character varying(100)

后端 未结 11 449
北恋
北恋 2021-01-31 02:37

I have a Django web site running a mini CMS we\'ve built internally years ago, it\'s using postgresql. When saving a simple title and a paragraph of text I get the following err

11条回答
  •  走了就别回头了
    2021-01-31 03:04

    First, try setting max_length to something reasonable on all applicable field types in your model.

    For example: MyText = models.CharField(max_length=2000)

    If you don't set a max_length, your database might be applying a default max_length, shorter than the length of your input data, causing your value too long for type character error.

    If that doesn't work and you started in SQLite and changed databases to PostgreSQL, the previous migrations from SQLite might be interfering with the new PostgreSQL migrations.

    Go into the migrations folder for your project and delete the old migration files to get a fresh start. Then try makemigrations and migrate again :)

提交回复
热议问题