title: Postgres query won't populate a database table. Possible constraints interference?
body: <p>I have a table named <code>pool_hashrate</code> with columns: <code>id</code> (PK), <code>hashrate</code>, <code>network_id</code> (FK), <code>pool_id</code> (FK). I would like to populate them with a query:</p>
  
  <pre><code>insert into pool_hashrate (
      hashrate, network_id, pool_id
  )
  select
      i+i::double precision, i, i
  from generate_series(0, 15) AS i;
  </code></pre>
  
  <p>The tables were automatically generated via Hibernate. The SQL code snippet from pgAdmin:</p>
  
  <pre><code>CREATE TABLE public.pool_hashrate
  (
      id bigint NOT NULL DEFAULT nextval('pool_hashrate_id_seq'::regclass),
      hashrate double precision NOT NULL,
      network_id bigint NOT NULL,
      pool_id bigint NOT NULL,
  
      CONSTRAINT pool_hashrate_pkey PRIMARY KEY (id),
      CONSTRAINT fk52n7131wvbi6196idmf1wfb0e FOREIGN KEY (pool_id)
          REFERENCES public.pool_hashrate (id) MATCH SIMPLE
          ON UPDATE NO ACTION
          ON DELETE NO ACTION,
      CONSTRAINT fkjph0cotxu5udghsbbgtpysv66 FOREIGN KEY (network_id)
          REFERENCES public.network_hashrate (id) MATCH SIMPLE
          ON UPDATE NO ACTION
          ON DELETE NO ACTION
  )
  WITH (
      OIDS = FALSE
  )
  TABLESPACE pg_default;
  
  ALTER TABLE public.pool_hashrate
      OWNER to postgres;
  </code></pre>
  
  <p>Can constraints be the problem? When executing the query in pgAdmin I get the <code>rows affected -1</code> message.</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>I keep getting the error <code>Null value in column “network_id” violates not-null constraint when adding new item.</code> Why is <code>null</code> being added there, if it's supposed to be <code>i</code>?</p>
  
  <hr>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>In fact, before above query I am running 2 other queries to populate <code>network_hashrate</code> &amp; <code>pool_hashrate</code>. Those queries are: </p>
  
  <pre><code>insert into network_hashrate (
      rep_date, hashrate
  )
  select
      current_timestamp - (s.a || ' hour')::interval,
      s.a::double precision
  from generate_series(0, 15, 1) AS s(a);
  
  insert into pool_def (
      name, date_from
  )
  select
      left(md5(random()::text), 10),
      current_timestamp - (s.a || ' hour')::interval
  from generate_series(0, 15, 1) AS s(a);
  </code></pre>
  
  <p>So to answer your question, yes, I do have the records in <code>network_hashrate</code>. There should be no problem, I guess?</p>