简体   繁体   English

错误:在Postgres中多次指定了列

[英]ERROR: column specified more than once in Postgres

I am a Postgres newbie and i have the following table to create through c# code: 我是Postgres新手,我通过C#代码创建了下表:

string create = "CREATE TABLE " + articles
                    + "("
                       + " SEQU_NK SERIAL PRIMARY KEY,"
                       + " ARTICLE_NK bigint   NOT NULL,"
                       + " DEPOT_NK  bigint  NOT NULL  ,"
                       + " EXPED_NK  bigint NOT NULL,"
                       + " CLIENT_NK  bigint  NOT NULL,"
                       + " SIGNE_TRANSP character varying(2) NOT NULL,"
                       + " NB_PLIS_TOTAL bigint DEFAULT 0  ,"
                       + " DH_PREM_ETIQUETTE timestamp  DEFAULT '0001-01-01 00:00:00',"
                       + " DATE_DEPOT_ARTICLE character varying(10) DEFAULT NULL,"                    
                       + " ARTICLE_NK character varying(10)  references articles(ARTICLE_NK),"
                       + " DEPOT_NK character varying(10)  references depots(DEPOT_NK),"
                       + " EXPED_NK character varying(10)  references expeds(EXPED_NK),"
                       + " CLIENT_NK character varying(10)  references clients(CLIENT_NK),"
                    + ") ";

The also try to write query on PGAdmin3 : 还尝试在PGAdmin3上写查询:

CREATE TABLE articles( SEQU_NK SERIAL PRIMARY KEY,
                       ARTICLE_NK bigint   NOT NULL,
                        DEPOT_NK  bigint  NOT NULL  ,
                        EXPED_NK  bigint NOT NULL,
                       CLIENT_NK  bigint  NOT NULL,
                        SIGNE_TRANSP character varying(2) NOT NULL,
                        NB_PLIS_TOTAL bigint DEFAULT 0  , 
                        DH_PREM_ETIQUETTE timestamp  DEFAULT '0001-01-01 00:00:00',                      
                        ARTICLE_NK character varying(10)  references articles(ARTICLE_NK),
                        DEPOT_NK character varying(10)  references depots(DEPOT_NK),
                        EXPED_NK character varying(10)  references expeds(EXPED_NK),
                       CLIENT_NK character varying(10)  references clients(CLIENT_NK)) ;

And error obtained is : 得到的错误是:

ERROR:  column "article_nk" specified more than once
********** Error **********

ERROR: column "article_nk" specified more than once
SQL state: 42701

How to fix this error as it is a foreign key? 由于它是外键,如何解决此错误? As I am changing the query from Mysql to Postgres? 当我将查询从Mysql更改为Postgres时?

The equivlaent Mysql query is (which I am translating to Postgres is): 等价的Mysql查询是(我将其翻译为Postgres是):

CREATE TABLE IF NOT EXISTS `articles` (
  `SEQU_NK` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Auto: Numero sequence',
  `ARTICLE_NK` int(11) NOT NULL,
  `DEPOT_NK` int(11) NOT NULL DEFAULT '0',
  `EXPED_NK` int(11) NOT NULL,
  `CLIENT_NK` int(11) NOT NULL,
  `SIGNE_TRANSP` varchar(2) NOT NULL DEFAULT '',
  `NB_PLIS_TOTAL` int(11) DEFAULT '0',
  `DH_PREM_ETIQUETTE` datetime DEFAULT '0001-01-01 00:00:00',
  PRIMARY KEY (`SEQU_NK`),
  KEY `ARTICLE_NK` (`ARTICLE_NK`),
  KEY `DEPOT_NK` (`DEPOT_NK`),
  KEY `EXPED_NK` (`EXPED_NK`),
  KEY `CLIENT_NK` (`CLIENT_NK`),

) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ;

You have columns: 您有专栏:

ARTICLE_NK bigint NOT NULL,

and

ARTICLE_NK character varying(10) references articles(ARTICLE_NK)

postgres interprets second as a column. postgres将第二解释为一列。 not as a key... 不是关键...

You should use this syntax instead: 您应该改用以下语法:

CONSTRAINT ARTICLE_NK_FK FOREIGN KEY (ARTICLE_NK) REFERENCES articles (ARTICLE_NK)

CREATE TABLE manual with some examples CREATE TABLE手册和一些示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM