Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

null value in column violates not-null constraint PostgreSQL

Tags:

csv

postgresql

I'm trying to import a csv into PostgreSQL database table.When i executing the following query:

enter image description here

My table name is trendmania_video

COPY public.trendmania_video FROM 'C:\Users\Shahnawaz Irfan\Desktop\0.csv' DELIMITER ',' CSV HEADER;

a following error occurred:

ERROR:  null value in column "v_id" violates not-null constraint
DETAIL:  Failing row contains (null, null, UgzYr_WZlR73yFBnRdx4AaABAg, yar 
kindly ap urdu m b toturial bna lety wordpress k liye to hma..., null, null, 
null, null, null, null, null, null, null, null).
CONTEXT:  COPY trendmania_video, line 10: ",,UgzYr_WZlR73yFBnRdx4AaABAg,yar 
kindly ap urdu m b toturial bna lety wordpress k liye to hmari b he..."
SQL state: 23502

I also tried manually by using import button, but same error occurs.

like image 672
Shahnawaz Irfan Avatar asked Feb 10 '26 19:02

Shahnawaz Irfan


1 Answers

In your table trendmania_video, you have v_id to be not null which causes this issue. You one option is to get ride of the not null constrain:

ALTER TABLE public.trendmania_video ALTER COLUMN v_id DROP NOT NULL;

If this is a new table then it's better to recreate it with a new table with an auto-cremented id while v_id is another value.

CREATE TABLE trendmania_video(
   id SERIAL PRIMARY KEY,
   v_id VARCHAR
   --the rest of the columns
);
like image 117
MEDZ Avatar answered Feb 13 '26 17:02

MEDZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!