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

前端 未结 6 1062
时光取名叫无心
时光取名叫无心 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条回答
  •  我在风中等你
    2020-12-05 20:20

    You can make Django use longer fields for this model by monkey-patching the model prior to using it to create the database tables. In "manage.py", change:

    if __name__ == "__main__":
        execute_manager(settings)
    

    to:

    from django.contrib.auth.models import Permission
    if __name__ == "__main__":
        # Patch the field width to allow for our long model names
        Permission._meta.get_field('name').max_length=200
        Permission._meta.get_field('codename').max_length=200
        execute_manager(settings)
    

    This modifies the options on the field before (say) manage.py syncdb is run, so the databate table has nice wide varchar() fields. You don't need to do this when invoking your app, as you never attempt to modify the Permissions table whle running.

提交回复
热议问题