When I try posting into Shopware 6 database table, I get a 400
status response with additional details This value is too long. It should have 255 character or less.
The data field description which I am trying to update accepts longtext.
My database table is clu_product_text and the table column I want to update is description and accepts longtext. The 400 status Error message is "This value is too long. It should have 255 character or less."
Below is my code:
const { Component} = Shopware;
const { Criteria } = Shopware.Data;
Component.register('clu-administration-page', {
template,
inject: [
'repositoryFactory',
'syncService'
],
metaInfo() {
return {
title: this.$createTitle()
};
},
data: function () {
return {
description: "For writers, a random sentence can help them get their creative juices flowing. Since the topic of the sentence is completely unknown, it forces the writer to be creative when the sentence appears. There are a number of different ways a writer can use the random sentence for creativity. The most common way to use the sentence is to begin a story. Another option is to include it somewhere in the story. A much more difficult challenge is to use it to end a story. In any of these cases, it forces the writer to think creatively since they have no idea what sentence will appear from the tool.",
id: "34eh9037492h2781",
isLoading: true
}
},
computed: {
cluProductTextRepository() {
return this.repositoryFactory.create('clu_product_text');
},
},
methods: {
updateCluProductText(){
this.cluProductTextRepository
.get(this.id, Shopware.Context.api)
.then((update) => {
update.description = this.description;
this.cluProductTextRepository.save(update, Shopware.Context.api);
});
}
},
created() {
this.updateCluProductText();
}
});
The StringField
on the definition of your custom entitiy has a third parameter maxLength
which by default is set to 255. For longer text you should use the LongTextField
instead.
So I assume your entity definition looks something like this:
public function defineFields(): FieldCollection
{
return new FieldCollection([
... your other fields
new StringField('clu_product_text', 'cluProductText'),
]);
}
Instead you should use the LongTextField
:
public function defineFields(): FieldCollection
{
return new FieldCollection([
... your other fields
new LongTextField('clu_product_text', 'cluProductText'),
]);
}