Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding product with sales channel fails #7100

Open
SGFGOV opened this issue Apr 19, 2024 · 1 comment
Open

adding product with sales channel fails #7100

SGFGOV opened this issue Apr 19, 2024 · 1 comment

Comments

@SGFGOV
Copy link
Contributor

SGFGOV commented Apr 19, 2024

Hi

When i try to add a product along with the sales channel, it fails with the error below. If i ignore sales channel in my backend it works. But I'm unable to attach the sales channel after that also

error: null value in column "id" of relation "product_sales_channel" violates not-null constraint\n at Parser.parseErrorMessage (/node_modules/pg-protocol/dist/parser.js:287:98)\n at Parser.handlePacket (/node_modules/pg-protocol/dist/parser.js:126:29)\n at Parser.parse (/node_modules/pg-protocol/dist/parser.js:39:38)\n at Socket. (/node_modules/pg-protocol/dist/index.js:11:42)\n at Socket.emit (node:events:514:28)\n at Socket.emit (node:domain:489:12)\n at addChunk (node:internal/streams/readable:324:12)\n at readableAddChunk (node:internal/streams/readable:297:9)\n at Readable.push (node:internal/streams/readable:234:10)\n at TCP.onStreamRead (node:internal/stream_base_commons:190:23)\n at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {length: 350, name: 'error', severity: 'ERROR', c…, …}
code:
'23502'
column:
'id'
constraint:
undefined
dataType:
undefined
detail:
'Failing row contains (prod_01HVTNVK32ZTD3DHMT2PHCHWWB, sc_01HAR7GSYPPQJS4RNE57J28EYD, null, 2024-04-19 07:59:17.868847+00, 2024-04-19 07:59:17.868847+00, null).'
file:
'execMain.c'
hint:
undefined
internalPosition:
undefined
internalQuery:
undefined
length:
350
line:
'2003'
name:
'error'

@SGFGOV
Copy link
Contributor Author

SGFGOV commented Apr 19, 2024

A possible fix

CREATE SEQUENCE IF NOT EXISTS products_sales_channel_id_seq;

ALTER TABLE product_sales_channel ALTER COLUMN id SET DEFAULT nextval('product_sales_channel_id_seq');

CREATE OR REPLACE FUNCTION product_sales_channel_insert_trigger()
RETURNS TRIGGER AS $$
BEGIN
NEW.id := nextval('product_sales_channel_id_seq');
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER IF NOT EXISTS product_sales_channel_insert_trigger
BEFORE INSERT ON product_sales_channel
FOR EACH ROW
WHEN (NEW.id IS NULL)
EXECUTE FUNCTION product_sales_channel_insert_trigger();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant