Shopware 6 Update: JSON Column-Type Fehler beheben
Bei Shopware 6 Updates kann es zu JSON-Fehlern kommen, wenn Migrationen Spaltentypen ändern oder JSON-Daten validieren. Besonders häufig betroffen: custom_fields mit leeren Strings statt gültiger JSON-Objekte. In diesem Beitrag zeige ich dir, wie du diese Fehler findest und behebst.
Das Problem
Typische Fehlermeldungen:
Invalid JSON text: "Invalid value." at position 0
Oder:
Doctrine\DBAL\Exception\InvalidFieldNameException
Die Migration erwartet gültiges JSON, findet aber:
- Leere Strings (
'')- Den String
"null"statt echtemNULL- Ungültige JSON-Syntax
- Alte Serialisierungsformate
- Ungültige JSON-Syntax
- Den String
Häufig betroffene Spalten
JSON-Probleme treten besonders häufig in diesen Spalten auf:
- custom_fields – Produkteigenschaften, Kundenattribute
- config – Plugin-Konfigurationen
- payload – Flow-Builder, Mail-Templates
- translated – Übersetzungsdaten
- price – Preisstrukturen
Typische Szenarien:
- Shop wurde von Shopware 6.2–6.4 migriert
- Plugins haben Daten unsauber geschrieben
- Import-Skripte haben leere Werte gesetzt
- Manuelle SQL-Updates mit falschen Werten
- Import-Skripte haben leere Werte gesetzt
- Plugins haben Daten unsauber geschrieben
- Shop wurde von Shopware 6.2–6.4 migriert
- price – Preisstrukturen
- translated – Übersetzungsdaten
- payload – Flow-Builder, Mail-Templates
Ungültige JSON-Werte finden
MySQL bietet die Funktion JSON_VALID() zum Prüfen:
-- Produkte mit ungültigen custom_fields finden
SELECT id, product_number, custom_fields
FROM product
WHERE custom_fields IS NOT NULL
AND custom_fields != ''
AND JSON_VALID(custom_fields) = 0;
Leere Strings finden (häufigste Ursache):
-- Leere Strings in custom_fields
SELECT id, product_number
FROM product
WHERE custom_fields = '';
Auch Übersetzungstabellen prüfen:
SELECT product_id, custom_fields
FROM product_translation
WHERE custom_fields = ''
OR (custom_fields IS NOT NULL AND JSON_VALID(custom_fields) = 0);
Lösung: JSON-Werte reparieren
Leere Strings durch leeres JSON-Objekt ersetzen:
-- product Tabelle
UPDATE product
SET custom_fields = '{}'
WHERE custom_fields = '' OR custom_fields IS NULL;-- product_translation Tabelle
UPDATE product_translation
SET custom_fields = '{}'
WHERE custom_fields = '' OR custom_fields IS NULL;
Für andere Tabellen analog:
-- Kategorien
UPDATE category_translation
SET custom_fields = '{}'
WHERE custom_fields = '' OR custom_fields IS NULL;-- Kunden
UPDATE customer
SET custom_fields = '{}'
WHERE custom_fields = '' OR custom_fields IS NULL;
Danach Migration erneut starten:
php bin/console database:migrate --all
Komplexere JSON-Reparaturen
String "null" durch echtes NULL ersetzen:
UPDATE product
SET custom_fields = NULL
WHERE custom_fields = 'null';
Defekte JSON-Arrays reparieren:
-- Wenn Arrays mit Trailing Comma existieren
UPDATE product
SET custom_fields = REPLACE(custom_fields, ',}', '}')
WHERE custom_fields LIKE '%,}';UPDATE product
SET custom_fields = REPLACE(custom_fields, ',]', ']')
WHERE custom_fields LIKE '%,]';
Alle Tabellen mit custom_fields auf einmal prüfen:
-- Übersicht aller problematischen Einträge
SELECT 'product' as tbl, COUNT(*) as cnt FROM product WHERE custom_fields = ''
UNION SELECT 'product_translation', COUNT(*) FROM product_translation WHERE custom_fields = ''
UNION SELECT 'category_translation', COUNT(*) FROM category_translation WHERE custom_fields = ''
UNION SELECT 'customer', COUNT(*) FROM customer WHERE custom_fields = '';
Prävention für die Zukunft
Bei eigenen Plugins und Imports:
// Immer valides JSON schreiben
$customFields = $data['custom_fields'] ?? [];
if (empty($customFields)) {
$customFields = null; // NULL statt leerer String
}
Vor Updates prüfen:
-- Quick-Check für alle wichtigen Tabellen
SELECT
'product' as entity,
SUM(CASE WHEN custom_fields = '' THEN 1 ELSE 0 END) as empty_string,
SUM(CASE WHEN JSON_VALID(COALESCE(custom_fields, '{}')) = 0 THEN 1 ELSE 0 END) as invalid_json
FROM product;
Import-Skripte validieren:
- Leere Werte als
NULLoder{}schreiben- JSON vor dem Schreiben validieren
- Encoding (UTF-8) sicherstellen
- JSON vor dem Schreiben validieren
Fazit
JSON-Column-Type-Fehler entstehen meist durch historische Daten aus älteren Shopware-Versionen oder unsaubere Imports. Die Lösung ist einfach:
1. Ungültige Werte finden mit JSON_VALID() und Leerstring-Checks
2. Leere Strings durch {} ersetzen
3. Migration erneut starten
Besonders bei Shops, die von Shopware 6.2–6.4 stammen, solltest du vor jedem Update die JSON-Spalten prüfen. Das spart dir viel Zeit beim Troubleshooting.
Brauchst du Hilfe bei der Datenbereinigung? Als Shopware-Entwickler unterstütze ich dich gerne bei Updates und Migrationen.
Matthias Hanske
Shopware 6 Fullstack Developer
Ich helfe E-Commerce-Unternehmen dabei, das volle Potenzial aus ihrem Shopware-Shop herauszuholen.
Brauchst du Hilfe bei deinem Shopware-Projekt?
Ich unterstütze dich gerne bei Updates, Migrationen und Entwicklung.