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

后端 未结 11 450
北恋
北恋 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:18

    Django 2.1

    I encountered this problem while switching from sqlite3 to postgresql. Remove the migration files in each app's migrations folder except __init__.py Then re-run migration

    (venv)myapp$python manage.py makemigrations
    (venv)myapp$python manage.py migrate
    (venv)myapp$python manage.py runserver
    
    0 讨论(0)
  • 2021-01-31 03:18

    I realize the question is already answered but for others that come here when looking for the error message:

    In my case the problem was that my table name exceeded 50 characters. Apparently this is not allowed. Changing the table name solved the problem.

    Read more here: https://code.djangoproject.com/ticket/18959

    0 讨论(0)
  • 2021-01-31 03:21

    predefined fields in model.py creates the problem. Extend it to desired length, i think problem will be resolved.

    0 讨论(0)
  • 2021-01-31 03:27

    I also had this problem when using a filefield and was scratching my head for a while. Of course the default FileField instances are created with a 100 character limit.

    https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield

    0 讨论(0)
  • 2021-01-31 03:27

    i went through this same error. and when i made changes in the modele, i kept having the same error.

    Here is how i fixed it. It might be necessary to skip few migrations for the program to only use the migration where changes have been made for the CharField max_lenght.

    for that you have to run

    python manage.py showmigrations 
    

    to see which migrations have not been made.

    then you skip them until you get to the last with the command

    python manage.py migrate <app> 000_migration_number --fake 
    
    0 讨论(0)
提交回复
热议问题