impossibile inserire la riga nell'ID, ma la riga non esiste


8

Ecco lo strano problema che sto affrontando. Sto cercando di inserire i dati utilizzando la seguente query

insert into product_product 
(id, product_tmpl_id, make_equip, model_equip, name_template, serial_num_equip, location_equip, issue_date_equip, issue_to_equip, remarks_equip, pr, ch,  categ_id,valuation) 
values (700,700,'Nikon','Action 10x50 Lookout','Nikon Action 10x50 Lookout','671386','40 Wall St.','5/13/2004 12:00:00 AM','','OM''s OFFICE',62,72,502,'manual periodic');

Ottengo l'errore:

ERROR:  duplicate key value violates unique constraint "product_product_pkey"
DETAIL:  Key (id)=(700) already exists.

********** Error **********

ERROR: duplicate key value violates unique constraint "product_product_pkey"
SQL state: 23505
Detail: Key (id)=(700) already exists.

Ho eseguito la query di selezione su quel record in questo modo:

select * from product_product
where id=700

Restituisce colonne senza dati (anche i dati includono id)

Ho provato a eseguire la query di aggiornamento in questo modo:

update product_product set 
                        product_tmpl_id=700,
                        make_equip='Nikon', 
                        model_equip='Action 10x50 Lookout', 
                        name_template='Nikon Action 10x50 Lookout', 
                        serial_num_equip='671386', 
                        location_equip='40 Wall St.', 
                        issue_date_equip='5/13/2004 12:00:00 AM', 
                        issue_to_equip='',
                        remarks_equip='OM''s OFFICE', 
                        pr=62, 
                        ch=72, 
                        categ_id=502,valuation='manual periodic' where id=700;

il risultato è stato:

Query returned successfully: 0 rows affected, 1 ms execution time.

ho provato ad eliminare anche la query ma lo stesso output.

Mostra anche tutti i dati non mostra nulla come ID 700.

Non so perché questo stia accadendo.

Sono stato indicizzato e ho aspirato la mia tabella dalla manutenzione ma lo stesso risultato.

Fammi sapere cosa c'è che non va.

Grazie

modificare

ecco la mia tabella di creazione

CREATE TABLE product_product
(
  id serial NOT NULL,
  create_uid integer,
  create_date timestamp without time zone,
  write_date timestamp without time zone,
  write_uid integer,
  ean13 character varying(13), -- EAN13 Barcode
  color integer, -- Color Index
  image bytea, -- Image
  price_extra numeric, -- Variant Price Extra
  default_code character varying(64), -- Internal Reference
  name_template character varying(128), -- Template Name
  .....
  description_sale text,
  procure_method character varying,
  produce_delay double precision,
  uom_id integer,
  name character varying,
  office_equip character varying, -- Office(Equipment)
  lease_agreement_equip character varying, -- Lease Agreement
  reg_exp_date_equip character varying, -- Registration Expiration Date
  CONSTRAINT product_product_pkey PRIMARY KEY (id ),
  CONSTRAINT product_product_categ_temp2_fkey FOREIGN KEY (categ_temp2)
      REFERENCES product_category (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_categ_temp3_fkey FOREIGN KEY (categ_temp3)
      REFERENCES product_category (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_categ_temps_fkey FOREIGN KEY (categ_temps)
      REFERENCES product_category (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_categg_temp_fkey FOREIGN KEY (categg_temp)
      REFERENCES product_category (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_ch_fkey FOREIGN KEY (ch)
      REFERENCES product_category (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_create_uid_fkey FOREIGN KEY (create_uid)
      REFERENCES res_users (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_my_products_fkey FOREIGN KEY (my_products)
      REFERENCES product_product (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_phone_data_id_fkey FOREIGN KEY (phone_data_id)
      REFERENCES phone_datas (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_phone_id_fkey FOREIGN KEY (phone_id)
      REFERENCES phone_types (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_pr_fkey FOREIGN KEY (pr)
      REFERENCES product_category (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_product_tmpl_id_fkey FOREIGN KEY (product_tmpl_id)
      REFERENCES product_template (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE,
  CONSTRAINT product_product_subchild_fkey FOREIGN KEY (subchild)
      REFERENCES product_category (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_temp_id_fkey FOREIGN KEY (temp_id)
      REFERENCES product_category (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT product_product_write_uid_fkey FOREIGN KEY (write_uid)
      REFERENCES res_users (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL
)
WITH (
  OIDS=FALSE
);

Ho qualcosa come 200+ colonne, quindi le ho rimosse da qui ....

L'immagine delle ultime righe in product_product è inserisci qui la descrizione dell'immagine

Risposte:


3

L' ID colonna è definito come SERIAL che è simile alla proprietà AUTO_INCREMENT supportata da alcuni altri database. Quindi dovresti ometterlo nell'istruzione INSERT o usare la parola chiave DEFAULT e il nuovo ID verrà generato automaticamente.

Vedi sezione 8.1.4. Tipi di serie: http://www.postgresql.org/docs/9.3/static/datatype-numeric.html

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.