dify icon indicating copy to clipboard operation
dify copied to clipboard

value too long for type character varying(40)

Open zzyyll2 opened this issue 10 months ago • 14 comments

Self Checks

  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [x] Please do not modify this template :) and fill in all the required fields.

Dify version

1.0.0-beta.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

my settings: Image

Image

error log: [SQL: INSERT INTO dataset_collection_bindings (provider_name, model_name, type, collection_name) VALUES (%(provider_name)s, %(model_name)s, %(type)s, %(collection_name)s) RETURNING dataset_collection_bindings.id, dataset_collection_bindings.created_at] [parameters: {'provider_name': 'langgenius/openai_api_compatible/openai_api_compatible', 'model_name': 'text-embedding-3-small', 'type': 'dataset', 'collection_name': 'Vector_index_383d24b8_fe9f_4984_854f_78fc3be7e218_Node'}] (Background on this error at: https://sqlalche.me/e/20/9h9h)

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

zzyyll2 avatar Feb 18 '25 09:02 zzyyll2

perhaps provider_name's value 'langgenius/openai_api_compatible/openai_api_compatible', it's length is 51 > 40 why the value is 'langgenius/openai_api_compatible/openai_api_compatible' not 'openai_api_compatible'?

zzyyll2 avatar Feb 18 '25 09:02 zzyyll2

Hey @zzyyll2! I'm here to help you with any bugs, questions, or contributions you have. Let's solve this together!

The error "value too long for type character varying(40)" is occurring because the provider_name column in the dataset_collection_bindings table is defined with a maximum length of 40 characters. The value 'langgenius/openai_api_compatible/openai_api_compatible' exceeds this limit with a length of 51 characters [1].

To resolve this, you should ensure that the database migration to increase the column length has been applied. There is a migration script that alters the provider_name column in the embeddings table to allow for longer values, but it seems this change might not have been applied to the dataset_collection_bindings table. You should check if there is a similar migration for this table or consider creating one to increase the column length to accommodate longer values [2].

If the migration has not been applied, follow the process for applying database migrations in the Dify platform. If you are using Docker, ensure the MIGRATION_ENABLED environment variable is set to true, and restart the services. If running from source, manually run flask db upgrade in the api directory [3].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Feb 18 '25 09:02 dosubot[bot]

@dosu I have newly installed it, not upgraded from an old version, do I also need to perform these operations? If so, please indicate this in the document. Thank you.

zzyyll2 avatar Feb 18 '25 10:02 zzyyll2

Yes, even with a new installation of the Dify platform, you need to perform database migration operations. This is necessary to ensure that your database schema is up-to-date with the latest version of the platform. The documentation should indeed indicate this requirement to guide users through the installation process. You can perform the migration by running the flask db upgrade command in the appropriate directory [1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Feb 18 '25 10:02 dosubot[bot]

@dosu I found MIGRATION_ENABLED environment variable is set to true default.

Image

zzyyll2 avatar Feb 18 '25 10:02 zzyyll2

That's great to hear! Since the MIGRATION_ENABLED environment variable is set to true by default, the migrations should run automatically when you start the application. If you're still encountering the issue, try restarting your Docker containers to ensure the migrations are applied. If the problem persists, you might want to manually run flask db upgrade in the API directory to ensure all migrations are applied correctly. Let me know if you need further assistance!

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Feb 18 '25 10:02 dosubot[bot]

@dosu I have reviewed the code, branch is 1.0.0-beta.1,i search dataset_collection_bindings, result below picture:

Image

There is not a migration script that alters the provider_name column in the embeddings table to allow for longer values.

look the code:

Image

thanks.

zzyyll2 avatar Feb 18 '25 10:02 zzyyll2

Hey @zzyyll2! It looks like you're diving deep into the migration scripts and database schema. While I can help with technical questions and bug fixes, I'm not equipped to review or analyze code directly. If you think I should be able to help with this, feel free to reach out to the Dosu Team. They'll be happy to hear your feedback! 😊

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Feb 18 '25 10:02 dosubot[bot]

@Dosu I solved this problem by following these steps:

  1. docker exec -it docker-db-1 bash
  2. psql -d dify
  3. ALTER TABLE dataset_collection_bindings ALTER COLUMN provider_name TYPE VARCHAR(255);
  4. \d dataset_collection_bindings; Table "public.dataset_collection_bindings" Column | Type | Collation | Nullable | Default
    -----------------+-----------------------------+-----------+----------+------------------------------ id | uuid | | not null | uuid_generate_v4() provider_name | character varying(255) | | not null | model_name | character varying(255) | | not null | collection_name | character varying(64) | | not null | created_at | timestamp without time zone | | not null | CURRENT_TIMESTAMP(0) type | character varying(40) | | not null | 'dataset'::character varying Indexes: "dataset_collection_bindings_pkey" PRIMARY KEY, btree (id) "provider_model_name_idx" btree (provider_name, model_name)

zzyyll2 avatar Feb 19 '25 10:02 zzyyll2

Hey @zzyyll2! It sounds like you've been busy and found a solution to your issue—great job! 🎉 However, I'm here to help with bugs, technical questions, and engineering knowledge, not to review or validate solutions. If you think I should be able to help with this kind of request, feel free to reach out to the Dosu Team. They'll be happy to hear your feedback! 😊

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Feb 19 '25 10:02 dosubot[bot]

@dosu I solved this problem by following these steps:

  1. docker exec -it docker-db-1 bash
  2. psql -d dify
  3. ALTER TABLE dataset_collection_bindings ALTER COLUMN provider_name TYPE VARCHAR(255);
  4. \d dataset_collection_bindings; Table "public.dataset_collection_bindings" Column | Type | Collation | Nullable | Default -----------------+-----------------------------+-----------+----------+------------------------------ id | uuid | | not null | uuid_generate_v4() provider_name | character varying(255) | | not null | model_name | character varying(255) | | not null | collection_name | character varying(64) | | not null | created_at | timestamp without time zone | | not null | CURRENT_TIMESTAMP(0) type | character varying(40) | | not null | 'dataset'::character varying Indexes: "dataset_collection_bindings_pkey" PRIMARY KEY, btree (id) "provider_model_name_idx" btree (provider_name, model_name)

thank you , it help me

kkjinping avatar Feb 28 '25 08:02 kkjinping

@dosu I solved this problem by following these steps:

  1. docker exec -it docker-db-1 bash
  2. psql -d dify
  3. ALTER TABLE dataset_collection_bindings ALTER COLUMN provider_name TYPE VARCHAR(255);
  4. \d dataset_collection_bindings; Table "public.dataset_collection_bindings" Column | Type | Collation | Nullable | Default -----------------+-----------------------------+-----------+----------+------------------------------ id | uuid | | not null | uuid_generate_v4() provider_name | character varying(255) | | not null | model_name | character varying(255) | | not null | collection_name | character varying(64) | | not null | created_at | timestamp without time zone | | not null | CURRENT_TIMESTAMP(0) type | character varying(40) | | not null | 'dataset'::character varying Indexes: "dataset_collection_bindings_pkey" PRIMARY KEY, btree (id) "provider_model_name_idx" btree (provider_name, model_name)

It works for me as well. However, since Dify is using PostgreSQL, we can replace all instances of VARCHAR(XXX) with the text type.

KangbingZhao avatar Mar 05 '25 14:03 KangbingZhao

@dosu I solved this problem by following these steps:

  1. docker exec -it docker-db-1 bash
  2. psql -d dify
  3. ALTER TABLE dataset_collection_bindings ALTER COLUMN provider_name TYPE VARCHAR(255);
  4. \d dataset_collection_bindings; Table "public.dataset_collection_bindings" Column | Type | Collation | Nullable | Default -----------------+-----------------------------+-----------+----------+------------------------------ id | uuid | | not null | uuid_generate_v4() provider_name | character varying(255) | | not null | model_name | character varying(255) | | not null | collection_name | character varying(64) | | not null | created_at | timestamp without time zone | | not null | CURRENT_TIMESTAMP(0) type | character varying(40) | | not null | 'dataset'::character varying Indexes: "dataset_collection_bindings_pkey" PRIMARY KEY, btree (id) "provider_model_name_idx" btree (provider_name, model_name)

works for me as well, but 1 point confused me is that bellow commit seems don't work after pulling the latest commit. fix: (psycopg2.errors.StringDataRightTruncation) value too long for type character varying(40) Fixes https://github.com/langgenius/dify/issues/14593 (https://github.com/langgenius/dify/pull/14597)

baseline i used: Author: Hantaek Lim [email protected] Date: 2025/3/8 19:08:48 Committer: GitHub [email protected] Commit hash: f7e012d21658eb24a9e17462598195e909061d69

Fix: reranker OFF logic to preserve user setting (#15235)

Co-authored-by: crazywoola [email protected]

Scofield-Gu avatar Mar 09 '25 04:03 Scofield-Gu

@dosu I solved this problem by following these steps:

  1. docker exec -it docker-db-1 bash
  2. psql -d dify
  3. ALTER TABLE dataset_collection_bindings ALTER COLUMN provider_name TYPE VARCHAR(255);
  4. \d dataset_collection_bindings; Table "public.dataset_collection_bindings" Column | Type | Collation | Nullable | Default -----------------+-----------------------------+-----------+----------+------------------------------ id | uuid | | not null | uuid_generate_v4() provider_name | character varying(255) | | not null | model_name | character varying(255) | | not null | collection_name | character varying(64) | | not null | created_at | timestamp without time zone | | not null | CURRENT_TIMESTAMP(0) type | character varying(40) | | not null | 'dataset'::character varying Indexes: "dataset_collection_bindings_pkey" PRIMARY KEY, btree (id) "provider_model_name_idx" btree (provider_name, model_name)

感谢 解决了本地化部署推理模型 无法导入知识库的问题 'langgenius/openai_api_compatible/openai_api_compatible' 应该去掉一个'openai_api_compatible'

Windows55 avatar Mar 10 '25 06:03 Windows55

fix: (psycopg2.errors.StringDataRightTruncation) value too long for type character varying(40) Fixes https://github.com/langgenius/dify/issues/14593 (https://github.com/langgenius/dify/pull/14597)

crazywoola avatar Mar 12 '25 05:03 crazywoola